using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Windows.Media.Imaging;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Serialization;

/*=====================================================================
  This file is part of a Microsoft SQL Server Shared Source Application.
  Copyright (C) Microsoft Corporation.  All rights reserved.
 
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
======================================================= */

/// This file was partially generated from the data set designer, and then customized.  It won't roundtrip anymore.
/// TODO: Rewrite this to use fewer classes with better names and a simpler implementation.

/// This file shows one possible way of using the custom mirror .NET data provider to access data which is mirrored on the backend.  
/// It is possible to use the custom mirror .NET data provider without using this strongly typed data set.  This is just an example.

/// TODO: Consider implementing a LINQ provider so we don't need to use strongly typed data sets.

namespace Microsoft.SqlCommunity.FaultRetry {
    
    
    /// <summary>
    ///Represents a strongly typed in-memory cache of data for products and product categories.
    ///</summary>
    [Serializable()]
    [XmlSchemaProviderAttribute("GetTypedDataSetSchema")]
    [XmlRootAttribute("ProductDataSet")]
    public class ProductDataSet : DataSet {
        
        private ProductDataTable tableProduct;
        
        private ProductCategoryDataTable tableProductCategory;
        
        private DataRelation relationFK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID;
        
        private DataRelation relationFK_Product_ProductCategory_ProductCategoryID;
        
        private SchemaSerializationMode _schemaSerializationMode = SchemaSerializationMode.IncludeSchema;
        

        public ProductDataSet() {
            this.BeginInit();
            this.InitClass();
            CollectionChangeEventHandler schemaChangedHandler = new CollectionChangeEventHandler(this.SchemaChanged);
            base.Tables.CollectionChanged += schemaChangedHandler;
            base.Relations.CollectionChanged += schemaChangedHandler;
            this.EndInit();
        }
        

        protected ProductDataSet(SerializationInfo info, StreamingContext context) : 
                base(info, context, false) {
            if ((this.IsBinarySerialized(info, context) == true)) {
                this.InitVars(false);
                CollectionChangeEventHandler schemaChangedHandler1 = new CollectionChangeEventHandler(this.SchemaChanged);
                this.Tables.CollectionChanged += schemaChangedHandler1;
                this.Relations.CollectionChanged += schemaChangedHandler1;
                return;
            }
            string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string))));
            if ((this.DetermineSchemaSerializationMode(info, context) == SchemaSerializationMode.IncludeSchema)) {
                DataSet ds = new DataSet();
                ds.ReadXmlSchema(new XmlTextReader(new StringReader(strSchema)));
                if ((ds.Tables["Product"] != null)) {
                    base.Tables.Add(new ProductDataTable(ds.Tables["Product"]));
                }
                if ((ds.Tables["ProductCategory"] != null)) {
                    base.Tables.Add(new ProductCategoryDataTable(ds.Tables["ProductCategory"]));
                }
                this.DataSetName = ds.DataSetName;
                this.Prefix = ds.Prefix;
                this.Namespace = ds.Namespace;
                this.Locale = ds.Locale;
                this.CaseSensitive = ds.CaseSensitive;
                this.EnforceConstraints = ds.EnforceConstraints;
                this.Merge(ds, false, MissingSchemaAction.Add);
                this.InitVars();
            }
            else {
                this.ReadXmlSchema(new XmlTextReader(new StringReader(strSchema)));
            }
            this.GetSerializationData(info, context);
            CollectionChangeEventHandler schemaChangedHandler = new CollectionChangeEventHandler(this.SchemaChanged);
            base.Tables.CollectionChanged += schemaChangedHandler;
            this.Relations.CollectionChanged += schemaChangedHandler;
        }
        

        public ProductDataTable Product {
            get {
                return this.tableProduct;
            }
        }
        

        public ProductCategoryDataTable ProductCategory {
            get {
                return this.tableProductCategory;
            }
        }
        

        public override SchemaSerializationMode SchemaSerializationMode {
            get {
                return this._schemaSerializationMode;
            }
            set {
                this._schemaSerializationMode = value;
            }
        }
        

        public new DataTableCollection Tables {
            get {
                return base.Tables;
            }
        }
        

        public new DataRelationCollection Relations {
            get {
                return base.Relations;
            }
        }
        

        protected override void InitializeDerivedDataSet() {
            this.BeginInit();
            this.InitClass();
            this.EndInit();
        }
        

        public override DataSet Clone() {
            ProductDataSet cln = ((ProductDataSet)(base.Clone()));
            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return cln;
        }
        

        protected override bool ShouldSerializeTables() {
            return false;
        }
        

        protected override bool ShouldSerializeRelations() {
            return false;
        }
        

        protected override void ReadXmlSerializable(XmlReader reader) {
            if ((this.DetermineSchemaSerializationMode(reader) == SchemaSerializationMode.IncludeSchema)) {
                this.Reset();
                DataSet ds = new DataSet();
                ds.ReadXml(reader);
                if ((ds.Tables["Product"] != null)) {
                    base.Tables.Add(new ProductDataTable(ds.Tables["Product"]));
                }
                if ((ds.Tables["ProductCategory"] != null)) {
                    base.Tables.Add(new ProductCategoryDataTable(ds.Tables["ProductCategory"]));
                }
                this.DataSetName = ds.DataSetName;
                this.Prefix = ds.Prefix;
                this.Namespace = ds.Namespace;
                this.Locale = ds.Locale;
                this.CaseSensitive = ds.CaseSensitive;
                this.EnforceConstraints = ds.EnforceConstraints;
                this.Merge(ds, false, MissingSchemaAction.Add);
                this.InitVars();
            }
            else {
                this.ReadXml(reader);
                this.InitVars();
            }
        }
        

        protected override XmlSchema GetSchemaSerializable() {
            MemoryStream stream = new MemoryStream();
            this.WriteXmlSchema(new XmlTextWriter(stream, null));
            stream.Position = 0;
            return XmlSchema.Read(new XmlTextReader(stream), null);
        }

        internal XmlSchema GetSchemaSerializableInternal()
        {
            return this.GetSchemaSerializable();
        }

        internal void InitVars() {
            this.InitVars(true);
        }
        

        internal void InitVars(bool initTable) {
            this.tableProduct = ((ProductDataTable)(base.Tables["Product"]));
            if ((initTable == true)) {
                if ((this.tableProduct != null)) {
                    this.tableProduct.InitVars();
                }
            }
            this.tableProductCategory = ((ProductCategoryDataTable)(base.Tables["ProductCategory"]));
            if ((initTable == true)) {
                if ((this.tableProductCategory != null)) {
                    this.tableProductCategory.InitVars();
                }
            }
            this.relationFK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID = this.Relations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"];
            this.relationFK_Product_ProductCategory_ProductCategoryID = this.Relations["FK_Product_ProductCategory_ProductCategoryID"];
        }
        

        private void InitClass() {
            this.DataSetName = "Product";
            this.Prefix = "";
            this.Namespace = "http://tempuri.org/Product.xsd";
            this.EnforceConstraints = true;
            this.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema;
            this.tableProduct = new ProductDataTable();
            base.Tables.Add(this.tableProduct);
            this.tableProductCategory = new ProductCategoryDataTable();
            base.Tables.Add(this.tableProductCategory);
            this.relationFK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID = new DataRelation("FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID", new DataColumn[] {
                        this.tableProductCategory.ProductCategoryIDColumn}, new DataColumn[] {
                        this.tableProductCategory.ParentProductCategoryIDColumn}, false);
            this.Relations.Add(this.relationFK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID);
            this.relationFK_Product_ProductCategory_ProductCategoryID = new DataRelation("FK_Product_ProductCategory_ProductCategoryID", new DataColumn[] {
                        this.tableProductCategory.ProductCategoryIDColumn}, new DataColumn[] {
                        this.tableProduct.ProductCategoryIDColumn}, false);
            this.Relations.Add(this.relationFK_Product_ProductCategory_ProductCategoryID);
        }
        

        private bool ShouldSerialize_Product() {
            return false;
        }
        

        private bool ShouldSerializeProductCategory() {
            return false;
        }
        

        private void SchemaChanged(object sender, CollectionChangeEventArgs e) {
            if ((e.Action == CollectionChangeAction.Remove)) {
                this.InitVars();
            }
        }
        

        public static XmlSchemaComplexType GetTypedDataSetSchema(XmlSchemaSet xs) {
            ProductDataSet ds = new ProductDataSet();
            XmlSchemaComplexType type = new XmlSchemaComplexType();
            XmlSchemaSequence sequence = new XmlSchemaSequence();
            XmlSchemaAny any = new XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace)) {
                MemoryStream s1 = new MemoryStream();
                MemoryStream s2 = new MemoryStream();
                try {
                    XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) {
                        schema = ((XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length)) {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) 
                                        && (s1.ReadByte() == s2.ReadByte())); ) {
                                ;
                            }
                            if ((s1.Position == s1.Length)) {
                                return type;
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null)) {
                        s1.Close();
                    }
                    if ((s2 != null)) {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return type;
        }
        
        

        
      

    }
    

    /// <summary>
    ///Represents a set of products from the AdventureWorksLT database.
    ///</summary>
    [Serializable()]
    [XmlSchemaProviderAttribute("GetTypedTableSchema")]
    public class ProductDataTable : TypedTableBase<Product>
    {

        private DataColumn columnProductID;

        private DataColumn columnName;

        private DataColumn columnProductNumber;

        private DataColumn columnColor;

        private DataColumn columnStandardCost;

        private DataColumn columnListPrice;

        private DataColumn columnSize;

        private DataColumn columnWeight;

        private DataColumn columnProductCategoryID;

        private DataColumn columnProductModelID;

        private DataColumn columnSellStartDate;

        private DataColumn columnSellEndDate;

        private DataColumn columnDiscontinuedDate;

        private DataColumn columnThumbNailPhoto;

        private DataColumn columnThumbnailPhotoFileName;

        private DataColumn columnrowguid;

        private DataColumn columnModifiedDate;


        public ProductDataTable()
        {
            this.TableName = "Product";
            this.BeginInit();
            this.InitClass();
            this.EndInit();
        }


        internal ProductDataTable(DataTable table)
        {
            this.TableName = table.TableName;
            if ((table.CaseSensitive != table.DataSet.CaseSensitive))
            {
                this.CaseSensitive = table.CaseSensitive;
            }
            if ((table.Locale.ToString() != table.DataSet.Locale.ToString()))
            {
                this.Locale = table.Locale;
            }
            if ((table.Namespace != table.DataSet.Namespace))
            {
                this.Namespace = table.Namespace;
            }
            this.Prefix = table.Prefix;
            this.MinimumCapacity = table.MinimumCapacity;
        }


        protected ProductDataTable(SerializationInfo info, StreamingContext context) :
            base(info, context)
        {
            this.InitVars();
        }


        public DataColumn ProductIDColumn
        {
            get
            {
                return this.columnProductID;
            }
        }


        public DataColumn NameColumn
        {
            get
            {
                return this.columnName;
            }
        }


        public DataColumn ProductNumberColumn
        {
            get
            {
                return this.columnProductNumber;
            }
        }


        public DataColumn ColorColumn
        {
            get
            {
                return this.columnColor;
            }
        }


        public DataColumn StandardCostColumn
        {
            get
            {
                return this.columnStandardCost;
            }
        }


        public DataColumn ListPriceColumn
        {
            get
            {
                return this.columnListPrice;
            }
        }


        public DataColumn SizeColumn
        {
            get
            {
                return this.columnSize;
            }
        }


        public DataColumn WeightColumn
        {
            get
            {
                return this.columnWeight;
            }
        }


        public DataColumn ProductCategoryIDColumn
        {
            get
            {
                return this.columnProductCategoryID;
            }
        }


        public DataColumn ProductModelIDColumn
        {
            get
            {
                return this.columnProductModelID;
            }
        }


        public DataColumn SellStartDateColumn
        {
            get
            {
                return this.columnSellStartDate;
            }
        }


        public DataColumn SellEndDateColumn
        {
            get
            {
                return this.columnSellEndDate;
            }
        }


        public DataColumn DiscontinuedDateColumn
        {
            get
            {
                return this.columnDiscontinuedDate;
            }
        }


        public DataColumn ThumbNailPhotoColumn
        {
            get
            {
                return this.columnThumbNailPhoto;
            }
        }


        public DataColumn ThumbnailPhotoFileNameColumn
        {
            get
            {
                return this.columnThumbnailPhotoFileName;
            }
        }


        public DataColumn rowguidColumn
        {
            get
            {
                return this.columnrowguid;
            }
        }


        public DataColumn ModifiedDateColumn
        {
            get
            {
                return this.columnModifiedDate;
            }
        }



        public int Count
        {
            get
            {
                return this.Rows.Count;
            }
        }


        public Product this[int index]
        {
            get
            {
                return ((Product)(this.Rows[index]));
            }
        }

        public event ProductChangeEventHandler ProductRowChanging;

        public event ProductChangeEventHandler ProductRowChanged;

        public event ProductChangeEventHandler ProductRowDeleting;

        public event ProductChangeEventHandler ProductRowDeleted;

        internal void OnProductRowChanging(DataRowChangeEventArgs e)
        {
            if ((this.ProductRowChanging != null))
            {
                this.ProductRowChanging(this, new ProductChangeEvent(((Product)(e.Row)), e.Action));
            }
        }

        public void AddProductRow(Product row)
        {
            this.Rows.Add(row);
        }


        public Product AddProductRow(
                    string Name,
                    string ProductNumber,
                    string Color,
                    decimal StandardCost,
                    decimal ListPrice,
                    string Size,
                    decimal Weight,
                    ProductCategory parentProductCategoryRowByFK_Product_ProductCategory_ProductCategoryID,
                    int ProductModelID,
                    System.DateTime SellStartDate,
                    System.DateTime SellEndDate,
                    System.DateTime DiscontinuedDate,
                    byte[] ThumbNailPhoto,
                    string ThumbnailPhotoFileName,
                    System.Guid rowguid,
                    System.DateTime ModifiedDate)
        {
            Product rowProductRow = ((Product)(this.NewRow()));
            object[] columnValuesArray = new object[] {
                        null,
                        Name,
                        ProductNumber,
                        Color,
                        StandardCost,
                        ListPrice,
                        Size,
                        Weight,
                        null,
                        ProductModelID,
                        SellStartDate,
                        SellEndDate,
                        DiscontinuedDate,
                        ThumbNailPhoto,
                        ThumbnailPhotoFileName,
                        rowguid,
                        ModifiedDate};
            if ((parentProductCategoryRowByFK_Product_ProductCategory_ProductCategoryID != null))
            {
                columnValuesArray[8] = parentProductCategoryRowByFK_Product_ProductCategory_ProductCategoryID[0];
            }
            rowProductRow.ItemArray = columnValuesArray;
            this.Rows.Add(rowProductRow);
            return rowProductRow;
        }


        public Product FindByProductID(int ProductID)
        {
            return ((Product)(this.Rows.Find(new object[] {
                            ProductID})));
        }


        public override DataTable Clone()
        {
            ProductDataTable cln = ((ProductDataTable)(base.Clone()));
            cln.InitVars();
            return cln;
        }


        protected override DataTable CreateInstance()
        {
            return new ProductDataTable();
        }


        internal void InitVars()
        {
            this.columnProductID = base.Columns["ProductID"];
            this.columnName = base.Columns["Name"];
            this.columnProductNumber = base.Columns["ProductNumber"];
            this.columnColor = base.Columns["Color"];
            this.columnStandardCost = base.Columns["StandardCost"];
            this.columnListPrice = base.Columns["ListPrice"];
            this.columnSize = base.Columns["Size"];
            this.columnWeight = base.Columns["Weight"];
            this.columnProductCategoryID = base.Columns["ProductCategoryID"];
            this.columnProductModelID = base.Columns["ProductModelID"];
            this.columnSellStartDate = base.Columns["SellStartDate"];
            this.columnSellEndDate = base.Columns["SellEndDate"];
            this.columnDiscontinuedDate = base.Columns["DiscontinuedDate"];
            this.columnThumbNailPhoto = base.Columns["ThumbNailPhoto"];
            this.columnThumbnailPhotoFileName = base.Columns["ThumbnailPhotoFileName"];
            this.columnrowguid = base.Columns["rowguid"];
            this.columnModifiedDate = base.Columns["ModifiedDate"];
        }


        private void InitClass()
        {
            this.columnProductID = new DataColumn("ProductID", typeof(int), null, MappingType.Element);
            base.Columns.Add(this.columnProductID);
            this.columnName = new DataColumn("Name", typeof(string), null, MappingType.Element);
            base.Columns.Add(this.columnName);
            this.columnProductNumber = new DataColumn("ProductNumber", typeof(string), null, MappingType.Element);
            base.Columns.Add(this.columnProductNumber);
            this.columnColor = new DataColumn("Color", typeof(string), null, MappingType.Element);
            base.Columns.Add(this.columnColor);
            this.columnStandardCost = new DataColumn("StandardCost", typeof(decimal), null, MappingType.Element);
            base.Columns.Add(this.columnStandardCost);
            this.columnListPrice = new DataColumn("ListPrice", typeof(decimal), null, MappingType.Element);
            base.Columns.Add(this.columnListPrice);
            this.columnSize = new DataColumn("Size", typeof(string), null, MappingType.Element);
            base.Columns.Add(this.columnSize);
            this.columnWeight = new DataColumn("Weight", typeof(decimal), null, MappingType.Element);
            base.Columns.Add(this.columnWeight);
            this.columnProductCategoryID = new DataColumn("ProductCategoryID", typeof(int), null, MappingType.Element);
            base.Columns.Add(this.columnProductCategoryID);
            this.columnProductModelID = new DataColumn("ProductModelID", typeof(int), null, MappingType.Element);
            base.Columns.Add(this.columnProductModelID);
            this.columnSellStartDate = new DataColumn("SellStartDate", typeof(DateTime), null, MappingType.Element);
            base.Columns.Add(this.columnSellStartDate);
            this.columnSellEndDate = new DataColumn("SellEndDate", typeof(DateTime), null, MappingType.Element);
            base.Columns.Add(this.columnSellEndDate);
            this.columnDiscontinuedDate = new DataColumn("DiscontinuedDate", typeof(DateTime), null, MappingType.Element);
            base.Columns.Add(this.columnDiscontinuedDate);
            this.columnThumbNailPhoto = new DataColumn("ThumbNailPhoto", typeof(byte[]), null, MappingType.Element);
            base.Columns.Add(this.columnThumbNailPhoto);
            this.columnThumbnailPhotoFileName = new DataColumn("ThumbnailPhotoFileName", typeof(string), null, MappingType.Element);
            base.Columns.Add(this.columnThumbnailPhotoFileName);
            this.columnrowguid = new DataColumn("rowguid", typeof(Guid), null, MappingType.Element);
            base.Columns.Add(this.columnrowguid);
            this.columnModifiedDate = new DataColumn("ModifiedDate", typeof(DateTime), null, MappingType.Element);
            base.Columns.Add(this.columnModifiedDate);
            this.Constraints.Add(new UniqueConstraint("Constraint1", new DataColumn[] {
                                this.columnProductID}, true));
            this.columnProductID.AutoIncrement = true;
            this.columnProductID.AutoIncrementSeed = -1;
            this.columnProductID.AutoIncrementStep = -1;
            this.columnProductID.AllowDBNull = false;
            this.columnProductID.ReadOnly = true;
            this.columnProductID.Unique = true;
            this.columnName.AllowDBNull = false;
            this.columnName.MaxLength = 50;
            this.columnProductNumber.AllowDBNull = false;
            this.columnProductNumber.MaxLength = 25;
            this.columnColor.MaxLength = 15;
            this.columnStandardCost.AllowDBNull = false;
            this.columnListPrice.AllowDBNull = false;
            this.columnSize.MaxLength = 5;
            this.columnSellStartDate.AllowDBNull = false;
            this.columnThumbnailPhotoFileName.MaxLength = 50;
            this.columnrowguid.AllowDBNull = false;
            this.columnModifiedDate.AllowDBNull = false;
        }


        public Product NewProductRow()
        {
            return ((Product)(this.NewRow()));
        }


        protected override DataRow NewRowFromBuilder(DataRowBuilder builder)
        {
            return new Product(builder);
        }


        protected override Type GetRowType()
        {
            return typeof(Product);
        }


        protected override void OnRowChanged(DataRowChangeEventArgs e)
        {
            base.OnRowChanged(e);
            if ((this.ProductRowChanged != null))
            {
                this.ProductRowChanged(this, new ProductChangeEvent(((Product)(e.Row)), e.Action));
            }
        }


        protected override void OnRowChanging(DataRowChangeEventArgs e)
        {
            base.OnRowChanging(e);

            if ((this.ProductRowChanging != null))
            {
                this.ProductRowChanging(this, new ProductChangeEvent(((Product)(e.Row)), e.Action));
            }
        }


        protected override void OnRowDeleted(DataRowChangeEventArgs e)
        {
            base.OnRowDeleted(e);
            if ((this.ProductRowDeleted != null))
            {
                this.ProductRowDeleted(this, new ProductChangeEvent(((Product)(e.Row)), e.Action));
            }
        }


        protected override void OnRowDeleting(DataRowChangeEventArgs e)
        {
            base.OnRowDeleting(e);
            if ((this.ProductRowDeleting != null))
            {
                this.ProductRowDeleting(this, new ProductChangeEvent(((Product)(e.Row)), e.Action));
            }
        }


        public void RemoveProductRow(Product row)
        {
            this.Rows.Remove(row);
        }


        public static XmlSchemaComplexType GetTypedTableSchema(XmlSchemaSet xs)
        {
            XmlSchemaComplexType type = new XmlSchemaComplexType();
            XmlSchemaSequence sequence = new XmlSchemaSequence();
            ProductDataSet ds = new ProductDataSet();
            XmlSchemaAny any1 = new XmlSchemaAny();
            any1.Namespace = "http://www.w3.org/2001/XMLSchema";
            any1.MinOccurs = new decimal(0);
            any1.MaxOccurs = decimal.MaxValue;
            any1.ProcessContents = XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any1);
            XmlSchemaAny any2 = new XmlSchemaAny();
            any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
            any2.MinOccurs = new decimal(1);
            any2.ProcessContents = XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any2);
            XmlSchemaAttribute attribute1 = new XmlSchemaAttribute();
            attribute1.Name = "namespace";
            attribute1.FixedValue = ds.Namespace;
            type.Attributes.Add(attribute1);
            XmlSchemaAttribute attribute2 = new XmlSchemaAttribute();
            attribute2.Name = "tableTypeName";
            attribute2.FixedValue = "ProductDataTable";
            type.Attributes.Add(attribute2);
            type.Particle = sequence;
            XmlSchema dsSchema = ds.GetSchemaSerializableInternal();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                MemoryStream s1 = new MemoryStream();
                MemoryStream s2 = new MemoryStream();
                try
                {
                    XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); )
                    {
                        schema = ((XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length)
                                        && (s1.ReadByte() == s2.ReadByte())); )
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return type;
                            }
                        }
                    }
                }
                finally
                {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return type;
        }
    }

    /// <summary>
    ///Represents products stored in the AdventureWorksLT database
    ///</summary>
    public class Product : DataRow
    {

        private ProductDataTable tableProduct;


        internal Product(DataRowBuilder rb) :
            base(rb)
        {
            this.tableProduct = ((ProductDataTable)(this.Table));
        }


        public int ProductID
        {
            get
            {
                return ((int)(this[this.tableProduct.ProductIDColumn]));
            }
            set
            {
                this[this.tableProduct.ProductIDColumn] = value;
            }
        }


        public string Name
        {
            get
            {
                return ((string)(this[this.tableProduct.NameColumn]));
            }
            set
            {
                this[this.tableProduct.NameColumn] = value;
            }
        }


        public string ProductNumber
        {
            get
            {
                return ((string)(this[this.tableProduct.ProductNumberColumn]));
            }
            set
            {
                this[this.tableProduct.ProductNumberColumn] = value;
            }
        }


        public string Color
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableProduct.ColorColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'Color\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.ColorColumn] = value;
            }
        }


        public decimal StandardCost
        {
            get
            {
                return ((decimal)(this[this.tableProduct.StandardCostColumn]));
            }
            set
            {
                this[this.tableProduct.StandardCostColumn] = value;
            }
        }


        public decimal ListPrice
        {
            get
            {
                return ((decimal)(this[this.tableProduct.ListPriceColumn]));
            }
            set
            {
                this[this.tableProduct.ListPriceColumn] = value;
            }
        }


        public string Size
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableProduct.SizeColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'Size\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.SizeColumn] = value;
            }
        }


        public decimal Weight
        {
            get
            {
                try
                {
                    return ((decimal)(this[this.tableProduct.WeightColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'Weight\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.WeightColumn] = value;
            }
        }


        public int ProductCategoryID
        {
            get
            {
                try
                {
                    return ((int)(this[this.tableProduct.ProductCategoryIDColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'ProductCategoryID\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.ProductCategoryIDColumn] = value;
            }
        }


        public int ProductModelID
        {
            get
            {
                try
                {
                    return ((int)(this[this.tableProduct.ProductModelIDColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'ProductModelID\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.ProductModelIDColumn] = value;
            }
        }


        public System.DateTime SellStartDate
        {
            get
            {
                return ((DateTime)(this[this.tableProduct.SellStartDateColumn]));
            }
            set
            {
                this[this.tableProduct.SellStartDateColumn] = value;
            }
        }


        public System.DateTime SellEndDate
        {
            get
            {
                try
                {
                    return ((DateTime)(this[this.tableProduct.SellEndDateColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'SellEndDate\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.SellEndDateColumn] = value;
            }
        }


        public System.DateTime DiscontinuedDate
        {
            get
            {
                try
                {
                    return ((DateTime)(this[this.tableProduct.DiscontinuedDateColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'DiscontinuedDate\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.DiscontinuedDateColumn] = value;
            }
        }


        public byte[] ThumbNailPhoto
        {
            get
            {
                try
                {
                    return ((byte[])(this[this.tableProduct.ThumbNailPhotoColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'ThumbNailPhoto\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.ThumbNailPhotoColumn] = value;
            }
        }

        private BitmapSource _cachedSource = null;
        public BitmapSource ThumbNail
        {
            get
            {
                if (_cachedSource == null)
                {
                    GifBitmapDecoder decoder = new GifBitmapDecoder(new MemoryStream(this.ThumbNailPhoto), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                    _cachedSource = decoder.Frames[0];
                }

                return _cachedSource;

            }
        }

        public string ThumbnailPhotoFileName
        {
            get
            {
                try
                {
                    return ((string)(this[this.tableProduct.ThumbnailPhotoFileNameColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'ThumbnailPhotoFileName\' in table \'Product\' is DBNull.", e);
                }
            }
            set
            {
                this[this.tableProduct.ThumbnailPhotoFileNameColumn] = value;
            }
        }


        public System.Guid rowguid
        {
            get
            {
                return ((Guid)(this[this.tableProduct.rowguidColumn]));
            }
            set
            {
                this[this.tableProduct.rowguidColumn] = value;
            }
        }


        public System.DateTime ModifiedDate
        {
            get
            {
                return ((DateTime)(this[this.tableProduct.ModifiedDateColumn]));
            }
            set
            {
                this[this.tableProduct.ModifiedDateColumn] = value;
            }
        }


        public ProductCategory ProductCategoryRow
        {
            get
            {
                return ((ProductCategory)(this.GetParentRow(this.Table.ParentRelations["FK_Product_ProductCategory_ProductCategoryID"])));
            }
            set
            {
                this.SetParentRow(value, this.Table.ParentRelations["FK_Product_ProductCategory_ProductCategoryID"]);
            }
        }


        public bool IsColorNull()
        {
            return this.IsNull(this.tableProduct.ColorColumn);
        }


        public void SetColorNull()
        {
            this[this.tableProduct.ColorColumn] = Convert.DBNull;
        }


        public bool IsSizeNull()
        {
            return this.IsNull(this.tableProduct.SizeColumn);
        }


        public void SetSizeNull()
        {
            this[this.tableProduct.SizeColumn] = Convert.DBNull;
        }


        public bool IsWeightNull()
        {
            return this.IsNull(this.tableProduct.WeightColumn);
        }


        public void SetWeightNull()
        {
            this[this.tableProduct.WeightColumn] = Convert.DBNull;
        }


        public bool IsProductCategoryIDNull()
        {
            return this.IsNull(this.tableProduct.ProductCategoryIDColumn);
        }


        public void SetProductCategoryIDNull()
        {
            this[this.tableProduct.ProductCategoryIDColumn] = Convert.DBNull;
        }


        public bool IsProductModelIDNull()
        {
            return this.IsNull(this.tableProduct.ProductModelIDColumn);
        }


        public void SetProductModelIDNull()
        {
            this[this.tableProduct.ProductModelIDColumn] = Convert.DBNull;
        }


        public bool IsSellEndDateNull()
        {
            return this.IsNull(this.tableProduct.SellEndDateColumn);
        }


        public void SetSellEndDateNull()
        {
            this[this.tableProduct.SellEndDateColumn] = Convert.DBNull;
        }


        public bool IsDiscontinuedDateNull()
        {
            return this.IsNull(this.tableProduct.DiscontinuedDateColumn);
        }


        public void SetDiscontinuedDateNull()
        {
            this[this.tableProduct.DiscontinuedDateColumn] = Convert.DBNull;
        }


        public bool IsThumbNailPhotoNull()
        {
            return this.IsNull(this.tableProduct.ThumbNailPhotoColumn);
        }


        public void SetThumbNailPhotoNull()
        {
            this[this.tableProduct.ThumbNailPhotoColumn] = Convert.DBNull;
        }


        public bool IsThumbnailPhotoFileNameNull()
        {
            return this.IsNull(this.tableProduct.ThumbnailPhotoFileNameColumn);
        }


        public void SetThumbnailPhotoFileNameNull()
        {
            this[this.tableProduct.ThumbnailPhotoFileNameColumn] = Convert.DBNull;
        }
    }

    /// <summary>
    ///Represents product categories stored in the AdventureWorksLT database.
    ///</summary>
    public class ProductCategory : DataRow
    {

        private ProductCategoryDataTable tableProductCategory;


        internal ProductCategory(DataRowBuilder rb) :
            base(rb)
        {
            this.tableProductCategory = ((ProductCategoryDataTable)(this.Table));
        }


        public int ProductCategoryID
        {
            get
            {
                return ((int)(this[this.tableProductCategory.ProductCategoryIDColumn]));
            }
            set
            {
                this[this.tableProductCategory.ProductCategoryIDColumn] = value;
            }
        }


        public int ParentProductCategoryID
        {
            get
            {
                try
                {
                    return ((int)(this[this.tableProductCategory.ParentProductCategoryIDColumn]));
                }
                catch (InvalidCastException e)
                {
                    throw new StrongTypingException("The value for column \'ParentProductCategoryID\' in table \'ProductCategory\' is DBNu" +
                            "ll.", e);
                }
            }
            set
            {
                this[this.tableProductCategory.ParentProductCategoryIDColumn] = value;
            }
        }


        public string Name
        {
            get
            {
                return ((string)(this[this.tableProductCategory.NameColumn]));
            }
            set
            {
                this[this.tableProductCategory.NameColumn] = value;
            }
        }


        public System.Guid rowguid
        {
            get
            {
                return ((Guid)(this[this.tableProductCategory.rowguidColumn]));
            }
            set
            {
                this[this.tableProductCategory.rowguidColumn] = value;
            }
        }


        public System.DateTime ModifiedDate
        {
            get
            {
                return ((DateTime)(this[this.tableProductCategory.ModifiedDateColumn]));
            }
            set
            {
                this[this.tableProductCategory.ModifiedDateColumn] = value;
            }
        }


        public ProductCategory ProductCategoryRowParent
        {
            get
            {
                return ((ProductCategory)(this.GetParentRow(this.Table.ParentRelations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"])));
            }
            set
            {
                this.SetParentRow(value, this.Table.ParentRelations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"]);
            }
        }


        public bool IsParentProductCategoryIDNull()
        {
            return this.IsNull(this.tableProductCategory.ParentProductCategoryIDColumn);
        }


        public void SetParentProductCategoryIDNull()
        {
            this[this.tableProductCategory.ParentProductCategoryIDColumn] = Convert.DBNull;
        }


        public ProductCategory[] GetProductCategoryRows()
        {
            if ((this.Table.ChildRelations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"] == null))
            {
                return new ProductCategory[0];
            }
            else
            {
                return ((ProductCategory[])(base.GetChildRows(this.Table.ChildRelations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"])));
            }
        }

        public ProductCategory[] ProductCategories
        {
            get { return GetProductCategoryRows(); }
        }

        public Product[] GetProductRows()
        {
            if ((this.Table.ChildRelations["FK_Product_ProductCategory_ProductCategoryID"] == null))
            {
                return new Product[0];
            }
            else
            {
                return ((Product[])(base.GetChildRows(this.Table.ChildRelations["FK_Product_ProductCategory_ProductCategoryID"])));
            }
        }

        public Product[] Products
        {
            get { return GetProductRows(); }
        }
    }

    /// <summary>
    /// Represents an event argument for an event when a product changes
    /// </summary>
    public class ProductChangeEvent : EventArgs
    {

        private Product eventRow;

        private DataRowAction eventAction;


        public ProductChangeEvent(Product row, DataRowAction action)
        {
            this.eventRow = row;
            this.eventAction = action;
        }


        public Product Row
        {
            get
            {
                return this.eventRow;
            }
        }


        public DataRowAction Action
        {
            get
            {
                return this.eventAction;
            }
        }
    }

    /// <summary>
    /// Represents an event argument for an event when a product category changes
    /// </summary>
    public class ProductCategoryChangeEvent : EventArgs
    {

        private ProductCategory eventRow;

        private DataRowAction eventAction;


        public ProductCategoryChangeEvent(ProductCategory row, DataRowAction action)
        {
            this.eventRow = row;
            this.eventAction = action;
        }


        public ProductCategory Row
        {
            get
            {
                return this.eventRow;
            }
        }


        public DataRowAction Action
        {
            get
            {
                return this.eventAction;
            }
        }
    }

    public delegate void ProductChangeEventHandler(object sender, ProductChangeEvent e);

    public delegate void ProductCategoryChangeEventHandler(object sender, ProductCategoryChangeEvent e);

    /// <summary>
    ///Represents the set of all product categories stored in the AdventureWorksLT database.
    ///</summary>
    [Serializable()]
    [XmlSchemaProviderAttribute("GetTypedTableSchema")]
    public class ProductCategoryDataTable : TypedTableBase<ProductCategory>
    {

        private DataColumn columnProductCategoryID;

        private DataColumn columnParentProductCategoryID;

        private DataColumn columnName;

        private DataColumn columnrowguid;

        private DataColumn columnModifiedDate;


        public ProductCategoryDataTable()
        {
            this.TableName = "ProductCategory";
            this.BeginInit();
            this.InitClass();
            this.EndInit();
        }


        internal ProductCategoryDataTable(DataTable table)
        {
            this.TableName = table.TableName;
            if ((table.CaseSensitive != table.DataSet.CaseSensitive))
            {
                this.CaseSensitive = table.CaseSensitive;
            }
            if ((table.Locale.ToString() != table.DataSet.Locale.ToString()))
            {
                this.Locale = table.Locale;
            }
            if ((table.Namespace != table.DataSet.Namespace))
            {
                this.Namespace = table.Namespace;
            }
            this.Prefix = table.Prefix;
            this.MinimumCapacity = table.MinimumCapacity;
        }


        protected ProductCategoryDataTable(SerializationInfo info, StreamingContext context) :
            base(info, context)
        {
            this.InitVars();
        }


        public DataColumn ProductCategoryIDColumn
        {
            get
            {
                return this.columnProductCategoryID;
            }
        }


        public DataColumn ParentProductCategoryIDColumn
        {
            get
            {
                return this.columnParentProductCategoryID;
            }
        }


        public DataColumn NameColumn
        {
            get
            {
                return this.columnName;
            }
        }


        public DataColumn rowguidColumn
        {
            get
            {
                return this.columnrowguid;
            }
        }


        public DataColumn ModifiedDateColumn
        {
            get
            {
                return this.columnModifiedDate;
            }
        }



        public int Count
        {
            get
            {
                return this.Rows.Count;
            }
        }


        public ProductCategory this[int index]
        {
            get
            {
                return ((ProductCategory)(this.Rows[index]));
            }
        }

        public event ProductCategoryChangeEventHandler ProductCategoryRowChanging;

        public event ProductCategoryChangeEventHandler ProductCategoryRowChanged;

        public event ProductCategoryChangeEventHandler ProductCategoryRowDeleting;

        public event ProductCategoryChangeEventHandler ProductCategoryRowDeleted;



        public void AddProductCategoryRow(ProductCategory row)
        {
            this.Rows.Add(row);
        }


        public ProductCategory AddProductCategoryRow(ProductCategory parentProductCategoryRowByFK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID, string Name, System.Guid rowguid, System.DateTime ModifiedDate)
        {
            ProductCategory rowProductCategoryRow = ((ProductCategory)(this.NewRow()));
            object[] columnValuesArray = new object[] {
                        null,
                        null,
                        Name,
                        rowguid,
                        ModifiedDate};
            if ((parentProductCategoryRowByFK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID != null))
            {
                columnValuesArray[1] = parentProductCategoryRowByFK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID[0];
            }
            rowProductCategoryRow.ItemArray = columnValuesArray;
            this.Rows.Add(rowProductCategoryRow);
            return rowProductCategoryRow;
        }


        public ProductCategory FindByProductCategoryID(int ProductCategoryID)
        {
            return ((ProductCategory)(this.Rows.Find(new object[] {
                            ProductCategoryID})));
        }


        public override DataTable Clone()
        {
            ProductCategoryDataTable cln = ((ProductCategoryDataTable)(base.Clone()));
            cln.InitVars();
            return cln;
        }


        protected override DataTable CreateInstance()
        {
            return new ProductCategoryDataTable();
        }


        internal void InitVars()
        {
            this.columnProductCategoryID = base.Columns["ProductCategoryID"];
            this.columnParentProductCategoryID = base.Columns["ParentProductCategoryID"];
            this.columnName = base.Columns["Name"];
            this.columnrowguid = base.Columns["rowguid"];
            this.columnModifiedDate = base.Columns["ModifiedDate"];
        }


        private void InitClass()
        {
            this.columnProductCategoryID = new DataColumn("ProductCategoryID", typeof(int), null, MappingType.Element);
            base.Columns.Add(this.columnProductCategoryID);
            this.columnParentProductCategoryID = new DataColumn("ParentProductCategoryID", typeof(int), null, MappingType.Element);
            base.Columns.Add(this.columnParentProductCategoryID);
            this.columnName = new DataColumn("Name", typeof(string), null, MappingType.Element);
            base.Columns.Add(this.columnName);
            this.columnrowguid = new DataColumn("rowguid", typeof(Guid), null, MappingType.Element);
            base.Columns.Add(this.columnrowguid);
            this.columnModifiedDate = new DataColumn("ModifiedDate", typeof(DateTime), null, MappingType.Element);
            base.Columns.Add(this.columnModifiedDate);
            this.Constraints.Add(new UniqueConstraint("Constraint1", new DataColumn[] {
                                this.columnProductCategoryID}, true));
            this.columnProductCategoryID.AutoIncrement = true;
            this.columnProductCategoryID.AutoIncrementSeed = -1;
            this.columnProductCategoryID.AutoIncrementStep = -1;
            this.columnProductCategoryID.AllowDBNull = false;
            this.columnProductCategoryID.ReadOnly = true;
            this.columnProductCategoryID.Unique = true;
            this.columnName.AllowDBNull = false;
            this.columnName.MaxLength = 50;
            this.columnrowguid.AllowDBNull = false;
            this.columnModifiedDate.AllowDBNull = false;
        }


        public ProductCategory NewProductCategoryRow()
        {
            return ((ProductCategory)(this.NewRow()));
        }


        protected override DataRow NewRowFromBuilder(DataRowBuilder builder)
        {
            return new ProductCategory(builder);
        }


        protected override Type GetRowType()
        {
            return typeof(ProductCategory);
        }


        protected override void OnRowChanged(DataRowChangeEventArgs e)
        {
            base.OnRowChanged(e);
            if ((this.ProductCategoryRowChanged != null))
            {
                this.ProductCategoryRowChanged(this, new ProductCategoryChangeEvent(((ProductCategory)(e.Row)), e.Action));
            }
        }


        protected override void OnRowChanging(DataRowChangeEventArgs e)
        {
            base.OnRowChanging(e);
            if ((this.ProductCategoryRowChanging != null))
            {
                this.ProductCategoryRowChanging(this, new ProductCategoryChangeEvent(((ProductCategory)(e.Row)), e.Action));
            }
        }


        protected override void OnRowDeleted(DataRowChangeEventArgs e)
        {
            base.OnRowDeleted(e);
            if ((this.ProductCategoryRowDeleted != null))
            {
                this.ProductCategoryRowDeleted(this, new ProductCategoryChangeEvent(((ProductCategory)(e.Row)), e.Action));
            }
        }


        protected override void OnRowDeleting(DataRowChangeEventArgs e)
        {
            base.OnRowDeleting(e);
            if ((this.ProductCategoryRowDeleting != null))
            {
                this.ProductCategoryRowDeleting(this, new ProductCategoryChangeEvent(((ProductCategory)(e.Row)), e.Action));
            }
        }


        public void RemoveProductCategoryRow(ProductCategory row)
        {
            this.Rows.Remove(row);
        }


        public static XmlSchemaComplexType GetTypedTableSchema(XmlSchemaSet xs)
        {
            XmlSchemaComplexType type = new XmlSchemaComplexType();
            XmlSchemaSequence sequence = new XmlSchemaSequence();
            ProductDataSet ds = new ProductDataSet();
            XmlSchemaAny any1 = new XmlSchemaAny();
            any1.Namespace = "http://www.w3.org/2001/XMLSchema";
            any1.MinOccurs = new decimal(0);
            any1.MaxOccurs = decimal.MaxValue;
            any1.ProcessContents = XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any1);
            XmlSchemaAny any2 = new XmlSchemaAny();
            any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
            any2.MinOccurs = new decimal(1);
            any2.ProcessContents = XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any2);
            XmlSchemaAttribute attribute1 = new XmlSchemaAttribute();
            attribute1.Name = "namespace";
            attribute1.FixedValue = ds.Namespace;
            type.Attributes.Add(attribute1);
            XmlSchemaAttribute attribute2 = new XmlSchemaAttribute();
            attribute2.Name = "tableTypeName";
            attribute2.FixedValue = "ProductCategoryDataTable";
            type.Attributes.Add(attribute2);
            type.Particle = sequence;
            XmlSchema dsSchema = ds.GetSchemaSerializableInternal();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                MemoryStream s1 = new MemoryStream();
                MemoryStream s2 = new MemoryStream();
                try
                {
                    XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); )
                    {
                        schema = ((XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length)
                                        && (s1.ReadByte() == s2.ReadByte())); )
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return type;
                            }
                        }
                    }
                }
                finally
                {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return type;
        }
    }

    /// <summary>
    ///Represents the connection and commands used to retrieve and save product information.
    ///</summary>
    public class ProductTableAdapter : Component
    {

        private FaultRetryDataAdapter _adapter;

        private FaultRetryConnection _connection;

        private SqlTransaction _transaction;

        private FaultRetryCommand[] _commandCollection;

        private bool _clearBeforeFill;


        public ProductTableAdapter()
        {
            this.ClearBeforeFill = true;
        }


        protected internal FaultRetryDataAdapter Adapter
        {
            get
            {
                if ((this._adapter == null))
                {
                    this.InitAdapter();
                }
                return this._adapter;
            }
        }


        internal FaultRetryConnection Connection
        {
            get
            {
                if ((this._connection == null))
                {
                    this.InitConnection();
                }
                return this._connection;
            }
            set
            {
                this._connection = value;
                if ((this.Adapter.InsertCommand != null))
                {
                    this.Adapter.InsertCommand.Connection = value;
                }
                if ((this.Adapter.DeleteCommand != null))
                {
                    this.Adapter.DeleteCommand.Connection = value;
                }
                if ((this.Adapter.UpdateCommand != null))
                {
                    this.Adapter.UpdateCommand.Connection = value;
                }
                for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1))
                {
                    if ((this.CommandCollection[i] != null))
                    {
                        ((FaultRetryCommand)(this.CommandCollection[i])).Connection = value;
                    }
                }
            }
        }


        internal SqlTransaction Transaction
        {
            get
            {
                return this._transaction;
            }
            set
            {
                this._transaction = value;
                for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1))
                {
                    this.CommandCollection[i].Transaction = this._transaction;
                }
                if (((this.Adapter != null)
                            && (this.Adapter.DeleteCommand != null)))
                {
                    this.Adapter.DeleteCommand.Transaction = this._transaction;
                }
                if (((this.Adapter != null)
                            && (this.Adapter.InsertCommand != null)))
                {
                    this.Adapter.InsertCommand.Transaction = this._transaction;
                }
                if (((this.Adapter != null)
                            && (this.Adapter.UpdateCommand != null)))
                {
                    this.Adapter.UpdateCommand.Transaction = this._transaction;
                }
            }
        }


        protected FaultRetryCommand[] CommandCollection
        {
            get
            {
                if ((this._commandCollection == null))
                {
                    this.InitCommandCollection();
                }
                return this._commandCollection;
            }
        }


        public bool ClearBeforeFill
        {
            get
            {
                return this._clearBeforeFill;
            }
            set
            {
                this._clearBeforeFill = value;
            }
        }


        private void InitAdapter()
        {
            this._adapter = new FaultRetryDataAdapter();
            DataTableMapping tableMapping = new DataTableMapping();
            tableMapping.SourceTable = "Table";
            tableMapping.DataSetTable = "Product";
            tableMapping.ColumnMappings.Add("ProductID", "ProductID");
            tableMapping.ColumnMappings.Add("Name", "Name");
            tableMapping.ColumnMappings.Add("ProductNumber", "ProductNumber");
            tableMapping.ColumnMappings.Add("Color", "Color");
            tableMapping.ColumnMappings.Add("StandardCost", "StandardCost");
            tableMapping.ColumnMappings.Add("ListPrice", "ListPrice");
            tableMapping.ColumnMappings.Add("Size", "Size");
            tableMapping.ColumnMappings.Add("Weight", "Weight");
            tableMapping.ColumnMappings.Add("ProductCategoryID", "ProductCategoryID");
            tableMapping.ColumnMappings.Add("ProductModelID", "ProductModelID");
            tableMapping.ColumnMappings.Add("SellStartDate", "SellStartDate");
            tableMapping.ColumnMappings.Add("SellEndDate", "SellEndDate");
            tableMapping.ColumnMappings.Add("DiscontinuedDate", "DiscontinuedDate");
            tableMapping.ColumnMappings.Add("ThumbNailPhoto", "ThumbNailPhoto");
            tableMapping.ColumnMappings.Add("ThumbnailPhotoFileName", "ThumbnailPhotoFileName");
            tableMapping.ColumnMappings.Add("rowguid", "rowguid");
            tableMapping.ColumnMappings.Add("ModifiedDate", "ModifiedDate");
            this._adapter.TableMappings.Add(tableMapping);
            this._adapter.DeleteCommand = new FaultRetryCommand();
            this._adapter.DeleteCommand.Connection = this.Connection;
            this._adapter.DeleteCommand.CommandText = @"DELETE FROM [SalesLT].[Product] WHERE (([ProductID] = @Original_ProductID) AND ([Name] = @Original_Name) AND ([ProductNumber] = @Original_ProductNumber) AND ((@IsNull_Color = 1 AND [Color] IS NULL) OR ([Color] = @Original_Color)) AND ([StandardCost] = @Original_StandardCost) AND ([ListPrice] = @Original_ListPrice) AND ((@IsNull_Size = 1 AND [Size] IS NULL) OR ([Size] = @Original_Size)) AND ((@IsNull_Weight = 1 AND [Weight] IS NULL) OR ([Weight] = @Original_Weight)) AND ((@IsNull_ProductCategoryID = 1 AND [ProductCategoryID] IS NULL) OR ([ProductCategoryID] = @Original_ProductCategoryID)) AND ((@IsNull_ProductModelID = 1 AND [ProductModelID] IS NULL) OR ([ProductModelID] = @Original_ProductModelID)) AND ([SellStartDate] = @Original_SellStartDate) AND ((@IsNull_SellEndDate = 1 AND [SellEndDate] IS NULL) OR ([SellEndDate] = @Original_SellEndDate)) AND ((@IsNull_DiscontinuedDate = 1 AND [DiscontinuedDate] IS NULL) OR ([DiscontinuedDate] = @Original_DiscontinuedDate)) AND ((@IsNull_ThumbnailPhotoFileName = 1 AND [ThumbnailPhotoFileName] IS NULL) OR ([ThumbnailPhotoFileName] = @Original_ThumbnailPhotoFileName)) AND ([rowguid] = @Original_rowguid) AND ([ModifiedDate] = @Original_ModifiedDate))";
            this._adapter.DeleteCommand.CommandType = CommandType.Text;
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ProductID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ProductNumber", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ProductNumber", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_Color", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "Color", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Color", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Color", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_StandardCost", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "StandardCost", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ListPrice", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "ListPrice", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_Size", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "Size", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Size", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Size", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_Weight", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "Weight", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Weight", SqlDbType.Decimal, 0, ParameterDirection.Input, 8, 2, "Weight", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_ProductModelID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductModelID", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ProductModelID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductModelID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_SellStartDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellStartDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_SellEndDate", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "SellEndDate", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_SellEndDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellEndDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_DiscontinuedDate", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "DiscontinuedDate", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_DiscontinuedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "DiscontinuedDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_ThumbnailPhotoFileName", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ThumbnailPhotoFileName", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ThumbnailPhotoFileName", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ThumbnailPhotoFileName", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.InsertCommand = new FaultRetryCommand();
            this._adapter.InsertCommand.Connection = this.Connection;
            this._adapter.InsertCommand.CommandText = @"INSERT INTO [SalesLT].[Product] ([Name], [ProductNumber], [Color], [StandardCost], [ListPrice], [Size], [Weight], [ProductCategoryID], [ProductModelID], [SellStartDate], [SellEndDate], [DiscontinuedDate], [ThumbNailPhoto], [ThumbnailPhotoFileName], [rowguid], [ModifiedDate]) VALUES (@Name, @ProductNumber, @Color, @StandardCost, @ListPrice, @Size, @Weight, @ProductCategoryID, @ProductModelID, @SellStartDate, @SellEndDate, @DiscontinuedDate, @ThumbNailPhoto, @ThumbnailPhotoFileName, @rowguid, @ModifiedDate);
SELECT ProductID, Name, ProductNumber, Color, StandardCost, ListPrice, Size, Weight, ProductCategoryID, ProductModelID, SellStartDate, SellEndDate, DiscontinuedDate, ThumbNailPhoto, ThumbnailPhotoFileName, rowguid, ModifiedDate FROM SalesLT.Product WHERE (ProductID = SCOPE_IDENTITY())";
            this._adapter.InsertCommand.CommandType = CommandType.Text;
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ProductNumber", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ProductNumber", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Color", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Color", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@StandardCost", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "StandardCost", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ListPrice", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "ListPrice", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Size", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Size", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Weight", SqlDbType.Decimal, 0, ParameterDirection.Input, 8, 2, "Weight", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ProductModelID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductModelID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@SellStartDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellStartDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@SellEndDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellEndDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@DiscontinuedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "DiscontinuedDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ThumbNailPhoto", SqlDbType.VarBinary, 0, ParameterDirection.Input, 0, 0, "ThumbNailPhoto", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ThumbnailPhotoFileName", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ThumbnailPhotoFileName", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand = new FaultRetryCommand();
            this._adapter.UpdateCommand.Connection = this.Connection;
            this._adapter.UpdateCommand.CommandText = "UPDATE [SalesLT].[Product] SET [Name] = @Name, [ProductNumber] = @ProductNumber, " +
                "[Color] = @Color, [StandardCost] = @StandardCost, [ListPrice] = @ListPrice, [Siz" +
                "e] = @Size, [Weight] = @Weight, [ProductCategoryID] = @ProductCategoryID, [Produ" +
                "ctModelID] = @ProductModelID, [SellStartDate] = @SellStartDate, [SellEndDate] = " +
                "@SellEndDate, [DiscontinuedDate] = @DiscontinuedDate, [ThumbNailPhoto] = @ThumbN" +
                "ailPhoto, [ThumbnailPhotoFileName] = @ThumbnailPhotoFileName, [rowguid] = @rowgu" +
                "id, [ModifiedDate] = @ModifiedDate WHERE (([ProductID] = @Original_ProductID) AN" +
                "D ([Name] = @Original_Name) AND ([ProductNumber] = @Original_ProductNumber) AND " +
                "((@IsNull_Color = 1 AND [Color] IS NULL) OR ([Color] = @Original_Color)) AND ([S" +
                "tandardCost] = @Original_StandardCost) AND ([ListPrice] = @Original_ListPrice) A" +
                "ND ((@IsNull_Size = 1 AND [Size] IS NULL) OR ([Size] = @Original_Size)) AND ((@I" +
                "sNull_Weight = 1 AND [Weight] IS NULL) OR ([Weight] = @Original_Weight)) AND ((@" +
                "IsNull_ProductCategoryID = 1 AND [ProductCategoryID] IS NULL) OR ([ProductCatego" +
                "ryID] = @Original_ProductCategoryID)) AND ((@IsNull_ProductModelID = 1 AND [Prod" +
                "uctModelID] IS NULL) OR ([ProductModelID] = @Original_ProductModelID)) AND ([Sel" +
                "lStartDate] = @Original_SellStartDate) AND ((@IsNull_SellEndDate = 1 AND [SellEn" +
                "dDate] IS NULL) OR ([SellEndDate] = @Original_SellEndDate)) AND ((@IsNull_Discon" +
                "tinuedDate = 1 AND [DiscontinuedDate] IS NULL) OR ([DiscontinuedDate] = @Origina" +
                "l_DiscontinuedDate)) AND ((@IsNull_ThumbnailPhotoFileName = 1 AND [ThumbnailPhot" +
                "oFileName] IS NULL) OR ([ThumbnailPhotoFileName] = @Original_ThumbnailPhotoFileN" +
                "ame)) AND ([rowguid] = @Original_rowguid) AND ([ModifiedDate] = @Original_Modifi" +
                "edDate));\r\nSELECT ProductID, Name, ProductNumber, Color, StandardCost, ListPrice" +
                ", Size, Weight, ProductCategoryID, ProductModelID, SellStartDate, SellEndDate, D" +
                "iscontinuedDate, ThumbNailPhoto, ThumbnailPhotoFileName, rowguid, ModifiedDate F" +
                "ROM SalesLT.Product WHERE (ProductID = @ProductID)";
            this._adapter.UpdateCommand.CommandType = CommandType.Text;
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ProductNumber", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ProductNumber", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Color", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Color", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@StandardCost", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "StandardCost", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ListPrice", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "ListPrice", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Size", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Size", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Weight", SqlDbType.Decimal, 0, ParameterDirection.Input, 8, 2, "Weight", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ProductModelID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductModelID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@SellStartDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellStartDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@SellEndDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellEndDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@DiscontinuedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "DiscontinuedDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ThumbNailPhoto", SqlDbType.VarBinary, 0, ParameterDirection.Input, 0, 0, "ThumbNailPhoto", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ThumbnailPhotoFileName", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ThumbnailPhotoFileName", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ProductID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ProductNumber", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ProductNumber", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_Color", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "Color", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Color", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Color", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_StandardCost", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "StandardCost", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ListPrice", SqlDbType.Money, 0, ParameterDirection.Input, 0, 0, "ListPrice", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_Size", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "Size", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Size", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Size", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_Weight", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "Weight", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Weight", SqlDbType.Decimal, 0, ParameterDirection.Input, 8, 2, "Weight", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_ProductModelID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductModelID", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ProductModelID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductModelID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_SellStartDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellStartDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_SellEndDate", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "SellEndDate", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_SellEndDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "SellEndDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_DiscontinuedDate", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "DiscontinuedDate", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_DiscontinuedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "DiscontinuedDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_ThumbnailPhotoFileName", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ThumbnailPhotoFileName", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ThumbnailPhotoFileName", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "ThumbnailPhotoFileName", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Int, 4, ParameterDirection.Input, 0, 0, "ProductID", DataRowVersion.Current, false, null, "", "", ""));
        }


        private void InitConnection()
        {
            this._connection = new FaultRetryConnection();
            this._connection.ConnectionString = Properties.Settings.Default.AdventureWorksLT2008ConnectionString;
        }


        private void InitCommandCollection()
        {
            this._commandCollection = new FaultRetryCommand[1];
            this._commandCollection[0] = new FaultRetryCommand();
            this._commandCollection[0].Connection = this.Connection;
            this._commandCollection[0].CommandText = "SELECT ProductID, Name, ProductNumber, Color, StandardCost, ListPrice, Size, Weig" +
                "ht, ProductCategoryID, ProductModelID, SellStartDate, SellEndDate, DiscontinuedD" +
                "ate, ThumbNailPhoto, ThumbnailPhotoFileName, rowguid, ModifiedDate FROM SalesLT." +
                "Product";
            this._commandCollection[0].CommandType = CommandType.Text;
        }


        public virtual int Fill(ProductDataTable dataTable)
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            if ((this.ClearBeforeFill == true))
            {
                dataTable.Clear();
            }
            int returnValue = this.Adapter.Fill(dataTable);
            return returnValue;
        }


        public virtual ProductDataTable GetData()
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            ProductDataTable dataTable = new ProductDataTable();
            this.Adapter.Fill(dataTable);
            return dataTable;
        }



        public virtual int Update(ProductDataTable dataTable)
        {
            return this.Adapter.Update(dataTable);
        }



        public virtual int Update(ProductDataSet dataSet)
        {
            return this.Adapter.Update(dataSet, "Product");
        }



        public virtual int Update(DataRow dataRow)
        {
            return this.Adapter.Update(new DataRow[] {
                        dataRow});
        }



        public virtual int Update(DataRow[] dataRows)
        {
            return this.Adapter.Update(dataRows);
        }



        public virtual int Delete(
                    int Original_ProductID,
                    string Original_Name,
                    string Original_ProductNumber,
                    string Original_Color,
                    decimal Original_StandardCost,
                    decimal Original_ListPrice,
                    string Original_Size,
                    Nullable<decimal> Original_Weight,
                    Nullable<int> Original_ProductCategoryID,
                    Nullable<int> Original_ProductModelID,
                    System.DateTime Original_SellStartDate,
                    Nullable<DateTime> Original_SellEndDate,
                    Nullable<DateTime> Original_DiscontinuedDate,
                    string Original_ThumbnailPhotoFileName,
                    System.Guid Original_rowguid,
                    System.DateTime Original_ModifiedDate)
        {
            this.Adapter.DeleteCommand.Parameters[0].Value = ((int)(Original_ProductID));
            if ((Original_Name == null))
            {
                throw new ArgumentNullException("Original_Name");
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[1].Value = ((string)(Original_Name));
            }
            if ((Original_ProductNumber == null))
            {
                throw new ArgumentNullException("Original_ProductNumber");
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[2].Value = ((string)(Original_ProductNumber));
            }
            if ((Original_Color == null))
            {
                this.Adapter.DeleteCommand.Parameters[3].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[4].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[3].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[4].Value = ((string)(Original_Color));
            }
            this.Adapter.DeleteCommand.Parameters[5].Value = ((decimal)(Original_StandardCost));
            this.Adapter.DeleteCommand.Parameters[6].Value = ((decimal)(Original_ListPrice));
            if ((Original_Size == null))
            {
                this.Adapter.DeleteCommand.Parameters[7].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[8].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[7].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[8].Value = ((string)(Original_Size));
            }
            if ((Original_Weight.HasValue == true))
            {
                this.Adapter.DeleteCommand.Parameters[9].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[10].Value = ((decimal)(Original_Weight.Value));
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[9].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[10].Value = DBNull.Value;
            }
            if ((Original_ProductCategoryID.HasValue == true))
            {
                this.Adapter.DeleteCommand.Parameters[11].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[12].Value = ((int)(Original_ProductCategoryID.Value));
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[11].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[12].Value = DBNull.Value;
            }
            if ((Original_ProductModelID.HasValue == true))
            {
                this.Adapter.DeleteCommand.Parameters[13].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[14].Value = ((int)(Original_ProductModelID.Value));
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[13].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[14].Value = DBNull.Value;
            }
            this.Adapter.DeleteCommand.Parameters[15].Value = ((System.DateTime)(Original_SellStartDate));
            if ((Original_SellEndDate.HasValue == true))
            {
                this.Adapter.DeleteCommand.Parameters[16].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[17].Value = ((System.DateTime)(Original_SellEndDate.Value));
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[16].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[17].Value = DBNull.Value;
            }
            if ((Original_DiscontinuedDate.HasValue == true))
            {
                this.Adapter.DeleteCommand.Parameters[18].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[19].Value = ((System.DateTime)(Original_DiscontinuedDate.Value));
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[18].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[19].Value = DBNull.Value;
            }
            if ((Original_ThumbnailPhotoFileName == null))
            {
                this.Adapter.DeleteCommand.Parameters[20].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[21].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[20].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[21].Value = ((string)(Original_ThumbnailPhotoFileName));
            }
            this.Adapter.DeleteCommand.Parameters[22].Value = ((System.Guid)(Original_rowguid));
            this.Adapter.DeleteCommand.Parameters[23].Value = ((System.DateTime)(Original_ModifiedDate));
            ConnectionState previousConnectionState = this.Adapter.DeleteCommand.Connection.State;
            if (((this.Adapter.DeleteCommand.Connection.State & ConnectionState.Open)
                        != ConnectionState.Open))
            {
                this.Adapter.DeleteCommand.Connection.Open();
            }
            try
            {
                int returnValue = this.Adapter.DeleteCommand.ExecuteNonQuery();
                return returnValue;
            }
            finally
            {
                if ((previousConnectionState == ConnectionState.Closed))
                {
                    this.Adapter.DeleteCommand.Connection.Close();
                }
            }
        }



        public virtual int Insert(
                    string Name,
                    string ProductNumber,
                    string Color,
                    decimal StandardCost,
                    decimal ListPrice,
                    string Size,
                    Nullable<decimal> Weight,
                    Nullable<int> ProductCategoryID,
                    Nullable<int> ProductModelID,
                    System.DateTime SellStartDate,
                    Nullable<DateTime> SellEndDate,
                    Nullable<DateTime> DiscontinuedDate,
                    byte[] ThumbNailPhoto,
                    string ThumbnailPhotoFileName,
                    System.Guid rowguid,
                    System.DateTime ModifiedDate)
        {
            if ((Name == null))
            {
                throw new ArgumentNullException("Name");
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[0].Value = ((string)(Name));
            }
            if ((ProductNumber == null))
            {
                throw new ArgumentNullException("ProductNumber");
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[1].Value = ((string)(ProductNumber));
            }
            if ((Color == null))
            {
                this.Adapter.InsertCommand.Parameters[2].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[2].Value = ((string)(Color));
            }
            this.Adapter.InsertCommand.Parameters[3].Value = ((decimal)(StandardCost));
            this.Adapter.InsertCommand.Parameters[4].Value = ((decimal)(ListPrice));
            if ((Size == null))
            {
                this.Adapter.InsertCommand.Parameters[5].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[5].Value = ((string)(Size));
            }
            if ((Weight.HasValue == true))
            {
                this.Adapter.InsertCommand.Parameters[6].Value = ((decimal)(Weight.Value));
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[6].Value = DBNull.Value;
            }
            if ((ProductCategoryID.HasValue == true))
            {
                this.Adapter.InsertCommand.Parameters[7].Value = ((int)(ProductCategoryID.Value));
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[7].Value = DBNull.Value;
            }
            if ((ProductModelID.HasValue == true))
            {
                this.Adapter.InsertCommand.Parameters[8].Value = ((int)(ProductModelID.Value));
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[8].Value = DBNull.Value;
            }
            this.Adapter.InsertCommand.Parameters[9].Value = ((System.DateTime)(SellStartDate));
            if ((SellEndDate.HasValue == true))
            {
                this.Adapter.InsertCommand.Parameters[10].Value = ((System.DateTime)(SellEndDate.Value));
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[10].Value = DBNull.Value;
            }
            if ((DiscontinuedDate.HasValue == true))
            {
                this.Adapter.InsertCommand.Parameters[11].Value = ((System.DateTime)(DiscontinuedDate.Value));
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[11].Value = DBNull.Value;
            }
            if ((ThumbNailPhoto == null))
            {
                this.Adapter.InsertCommand.Parameters[12].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[12].Value = ((byte[])(ThumbNailPhoto));
            }
            if ((ThumbnailPhotoFileName == null))
            {
                this.Adapter.InsertCommand.Parameters[13].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[13].Value = ((string)(ThumbnailPhotoFileName));
            }
            this.Adapter.InsertCommand.Parameters[14].Value = ((System.Guid)(rowguid));
            this.Adapter.InsertCommand.Parameters[15].Value = ((System.DateTime)(ModifiedDate));
            ConnectionState previousConnectionState = this.Adapter.InsertCommand.Connection.State;
            if (((this.Adapter.InsertCommand.Connection.State & ConnectionState.Open)
                        != ConnectionState.Open))
            {
                this.Adapter.InsertCommand.Connection.Open();
            }
            try
            {
                int returnValue = this.Adapter.InsertCommand.ExecuteNonQuery();
                return returnValue;
            }
            finally
            {
                if ((previousConnectionState == ConnectionState.Closed))
                {
                    this.Adapter.InsertCommand.Connection.Close();
                }
            }
        }



        public virtual int Update(
                    string Name,
                    string ProductNumber,
                    string Color,
                    decimal StandardCost,
                    decimal ListPrice,
                    string Size,
                    Nullable<decimal> Weight,
                    Nullable<int> ProductCategoryID,
                    Nullable<int> ProductModelID,
                    System.DateTime SellStartDate,
                    Nullable<DateTime> SellEndDate,
                    Nullable<DateTime> DiscontinuedDate,
                    byte[] ThumbNailPhoto,
                    string ThumbnailPhotoFileName,
                    System.Guid rowguid,
                    System.DateTime ModifiedDate,
                    int Original_ProductID,
                    string Original_Name,
                    string Original_ProductNumber,
                    string Original_Color,
                    decimal Original_StandardCost,
                    decimal Original_ListPrice,
                    string Original_Size,
                    Nullable<decimal> Original_Weight,
                    Nullable<int> Original_ProductCategoryID,
                    Nullable<int> Original_ProductModelID,
                    System.DateTime Original_SellStartDate,
                    Nullable<DateTime> Original_SellEndDate,
                    Nullable<DateTime> Original_DiscontinuedDate,
                    string Original_ThumbnailPhotoFileName,
                    System.Guid Original_rowguid,
                    System.DateTime Original_ModifiedDate,
                    int ProductID)
        {
            if ((Name == null))
            {
                throw new ArgumentNullException("Name");
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[0].Value = ((string)(Name));
            }
            if ((ProductNumber == null))
            {
                throw new ArgumentNullException("ProductNumber");
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[1].Value = ((string)(ProductNumber));
            }
            if ((Color == null))
            {
                this.Adapter.UpdateCommand.Parameters[2].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[2].Value = ((string)(Color));
            }
            this.Adapter.UpdateCommand.Parameters[3].Value = ((decimal)(StandardCost));
            this.Adapter.UpdateCommand.Parameters[4].Value = ((decimal)(ListPrice));
            if ((Size == null))
            {
                this.Adapter.UpdateCommand.Parameters[5].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[5].Value = ((string)(Size));
            }
            if ((Weight.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[6].Value = ((decimal)(Weight.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[6].Value = DBNull.Value;
            }
            if ((ProductCategoryID.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[7].Value = ((int)(ProductCategoryID.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[7].Value = DBNull.Value;
            }
            if ((ProductModelID.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[8].Value = ((int)(ProductModelID.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[8].Value = DBNull.Value;
            }
            this.Adapter.UpdateCommand.Parameters[9].Value = ((System.DateTime)(SellStartDate));
            if ((SellEndDate.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[10].Value = ((System.DateTime)(SellEndDate.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[10].Value = DBNull.Value;
            }
            if ((DiscontinuedDate.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[11].Value = ((System.DateTime)(DiscontinuedDate.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[11].Value = DBNull.Value;
            }
            if ((ThumbNailPhoto == null))
            {
                this.Adapter.UpdateCommand.Parameters[12].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[12].Value = ((byte[])(ThumbNailPhoto));
            }
            if ((ThumbnailPhotoFileName == null))
            {
                this.Adapter.UpdateCommand.Parameters[13].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[13].Value = ((string)(ThumbnailPhotoFileName));
            }
            this.Adapter.UpdateCommand.Parameters[14].Value = ((System.Guid)(rowguid));
            this.Adapter.UpdateCommand.Parameters[15].Value = ((System.DateTime)(ModifiedDate));
            this.Adapter.UpdateCommand.Parameters[16].Value = ((int)(Original_ProductID));
            if ((Original_Name == null))
            {
                throw new ArgumentNullException("Original_Name");
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[17].Value = ((string)(Original_Name));
            }
            if ((Original_ProductNumber == null))
            {
                throw new ArgumentNullException("Original_ProductNumber");
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[18].Value = ((string)(Original_ProductNumber));
            }
            if ((Original_Color == null))
            {
                this.Adapter.UpdateCommand.Parameters[19].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[20].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[19].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[20].Value = ((string)(Original_Color));
            }
            this.Adapter.UpdateCommand.Parameters[21].Value = ((decimal)(Original_StandardCost));
            this.Adapter.UpdateCommand.Parameters[22].Value = ((decimal)(Original_ListPrice));
            if ((Original_Size == null))
            {
                this.Adapter.UpdateCommand.Parameters[23].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[24].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[23].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[24].Value = ((string)(Original_Size));
            }
            if ((Original_Weight.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[25].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[26].Value = ((decimal)(Original_Weight.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[25].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[26].Value = DBNull.Value;
            }
            if ((Original_ProductCategoryID.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[27].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[28].Value = ((int)(Original_ProductCategoryID.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[27].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[28].Value = DBNull.Value;
            }
            if ((Original_ProductModelID.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[29].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[30].Value = ((int)(Original_ProductModelID.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[29].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[30].Value = DBNull.Value;
            }
            this.Adapter.UpdateCommand.Parameters[31].Value = ((System.DateTime)(Original_SellStartDate));
            if ((Original_SellEndDate.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[32].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[33].Value = ((System.DateTime)(Original_SellEndDate.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[32].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[33].Value = DBNull.Value;
            }
            if ((Original_DiscontinuedDate.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[34].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[35].Value = ((System.DateTime)(Original_DiscontinuedDate.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[34].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[35].Value = DBNull.Value;
            }
            if ((Original_ThumbnailPhotoFileName == null))
            {
                this.Adapter.UpdateCommand.Parameters[36].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[37].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[36].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[37].Value = ((string)(Original_ThumbnailPhotoFileName));
            }
            this.Adapter.UpdateCommand.Parameters[38].Value = ((System.Guid)(Original_rowguid));
            this.Adapter.UpdateCommand.Parameters[39].Value = ((System.DateTime)(Original_ModifiedDate));
            this.Adapter.UpdateCommand.Parameters[40].Value = ((int)(ProductID));
            ConnectionState previousConnectionState = this.Adapter.UpdateCommand.Connection.State;
            if (((this.Adapter.UpdateCommand.Connection.State & ConnectionState.Open)
                        != ConnectionState.Open))
            {
                this.Adapter.UpdateCommand.Connection.Open();
            }
            try
            {
                int returnValue = this.Adapter.UpdateCommand.ExecuteNonQuery();
                return returnValue;
            }
            finally
            {
                if ((previousConnectionState == ConnectionState.Closed))
                {
                    this.Adapter.UpdateCommand.Connection.Close();
                }
            }
        }



        public virtual int Update(
                    string Name,
                    string ProductNumber,
                    string Color,
                    decimal StandardCost,
                    decimal ListPrice,
                    string Size,
                    Nullable<decimal> Weight,
                    Nullable<int> ProductCategoryID,
                    Nullable<int> ProductModelID,
                    System.DateTime SellStartDate,
                    Nullable<DateTime> SellEndDate,
                    Nullable<DateTime> DiscontinuedDate,
                    byte[] ThumbNailPhoto,
                    string ThumbnailPhotoFileName,
                    System.Guid rowguid,
                    System.DateTime ModifiedDate,
                    int Original_ProductID,
                    string Original_Name,
                    string Original_ProductNumber,
                    string Original_Color,
                    decimal Original_StandardCost,
                    decimal Original_ListPrice,
                    string Original_Size,
                    Nullable<decimal> Original_Weight,
                    Nullable<int> Original_ProductCategoryID,
                    Nullable<int> Original_ProductModelID,
                    System.DateTime Original_SellStartDate,
                    Nullable<DateTime> Original_SellEndDate,
                    Nullable<DateTime> Original_DiscontinuedDate,
                    string Original_ThumbnailPhotoFileName,
                    System.Guid Original_rowguid,
                    System.DateTime Original_ModifiedDate)
        {
            return this.Update(Name, ProductNumber, Color, StandardCost, ListPrice, Size, Weight, ProductCategoryID, ProductModelID, SellStartDate, SellEndDate, DiscontinuedDate, ThumbNailPhoto, ThumbnailPhotoFileName, rowguid, ModifiedDate, Original_ProductID, Original_Name, Original_ProductNumber, Original_Color, Original_StandardCost, Original_ListPrice, Original_Size, Original_Weight, Original_ProductCategoryID, Original_ProductModelID, Original_SellStartDate, Original_SellEndDate, Original_DiscontinuedDate, Original_ThumbnailPhotoFileName, Original_rowguid, Original_ModifiedDate, Original_ProductID);
        }
    }

    /// <summary>
    ///Represents the connection and commands used to retrieve and save product category information.
    ///</summary>
    public class ProductCategoryTableAdapter : Component
    {

        private FaultRetryDataAdapter _adapter;

        private FaultRetryConnection _connection;

        private SqlTransaction _transaction;

        private FaultRetryCommand[] _commandCollection;

        private bool _clearBeforeFill;


        public ProductCategoryTableAdapter()
        {
            this.ClearBeforeFill = true;
        }


        protected internal FaultRetryDataAdapter Adapter
        {
            get
            {
                if ((this._adapter == null))
                {
                    this.InitAdapter();
                }
                return this._adapter;
            }
        }


        internal FaultRetryConnection Connection
        {
            get
            {
                if ((this._connection == null))
                {
                    this.InitConnection();
                }
                return this._connection;
            }
            set
            {
                this._connection = value;
                if ((this.Adapter.InsertCommand != null))
                {
                    this.Adapter.InsertCommand.Connection = value;
                }
                if ((this.Adapter.DeleteCommand != null))
                {
                    this.Adapter.DeleteCommand.Connection = value;
                }
                if ((this.Adapter.UpdateCommand != null))
                {
                    this.Adapter.UpdateCommand.Connection = value;
                }
                for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1))
                {
                    if ((this.CommandCollection[i] != null))
                    {
                        ((FaultRetryCommand)(this.CommandCollection[i])).Connection = value;
                    }
                }
            }
        }


        internal SqlTransaction Transaction
        {
            get
            {
                return this._transaction;
            }
            set
            {
                this._transaction = value;
                for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1))
                {
                    this.CommandCollection[i].Transaction = this._transaction;
                }
                if (((this.Adapter != null)
                            && (this.Adapter.DeleteCommand != null)))
                {
                    this.Adapter.DeleteCommand.Transaction = this._transaction;
                }
                if (((this.Adapter != null)
                            && (this.Adapter.InsertCommand != null)))
                {
                    this.Adapter.InsertCommand.Transaction = this._transaction;
                }
                if (((this.Adapter != null)
                            && (this.Adapter.UpdateCommand != null)))
                {
                    this.Adapter.UpdateCommand.Transaction = this._transaction;
                }
            }
        }


        protected FaultRetryCommand[] CommandCollection
        {
            get
            {
                if ((this._commandCollection == null))
                {
                    this.InitCommandCollection();
                }
                return this._commandCollection;
            }
        }


        public bool ClearBeforeFill
        {
            get
            {
                return this._clearBeforeFill;
            }
            set
            {
                this._clearBeforeFill = value;
            }
        }


        private void InitAdapter()
        {
            this._adapter = new FaultRetryDataAdapter();
            DataTableMapping tableMapping = new DataTableMapping();
            tableMapping.SourceTable = "Table";
            tableMapping.DataSetTable = "ProductCategory";
            tableMapping.ColumnMappings.Add("ProductCategoryID", "ProductCategoryID");
            tableMapping.ColumnMappings.Add("ParentProductCategoryID", "ParentProductCategoryID");
            tableMapping.ColumnMappings.Add("Name", "Name");
            tableMapping.ColumnMappings.Add("rowguid", "rowguid");
            tableMapping.ColumnMappings.Add("ModifiedDate", "ModifiedDate");
            this._adapter.TableMappings.Add(tableMapping);
            this._adapter.DeleteCommand = new FaultRetryCommand();
            this._adapter.DeleteCommand.Connection = this.Connection;
            this._adapter.DeleteCommand.CommandText = @"DELETE FROM [SalesLT].[ProductCategory] WHERE (([ProductCategoryID] = @Original_ProductCategoryID) AND ((@IsNull_ParentProductCategoryID = 1 AND [ParentProductCategoryID] IS NULL) OR ([ParentProductCategoryID] = @Original_ParentProductCategoryID)) AND ([Name] = @Original_Name) AND ([rowguid] = @Original_rowguid) AND ([ModifiedDate] = @Original_ModifiedDate))";
            this._adapter.DeleteCommand.CommandType = CommandType.Text;
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsNull_ParentProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ParentProductCategoryID", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ParentProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ParentProductCategoryID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.InsertCommand = new FaultRetryCommand();
            this._adapter.InsertCommand.Connection = this.Connection;
            this._adapter.InsertCommand.CommandText = @"INSERT INTO [SalesLT].[ProductCategory] ([ParentProductCategoryID], [Name], [rowguid], [ModifiedDate]) VALUES (@ParentProductCategoryID, @Name, @rowguid, @ModifiedDate);
SELECT ProductCategoryID, ParentProductCategoryID, Name, rowguid, ModifiedDate FROM SalesLT.ProductCategory WHERE (ProductCategoryID = SCOPE_IDENTITY())";
            this._adapter.InsertCommand.CommandType = CommandType.Text;
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ParentProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ParentProductCategoryID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand = new FaultRetryCommand();
            this._adapter.UpdateCommand.Connection = this.Connection;
            this._adapter.UpdateCommand.CommandText = @"UPDATE [SalesLT].[ProductCategory] SET [ParentProductCategoryID] = @ParentProductCategoryID, [Name] = @Name, [rowguid] = @rowguid, [ModifiedDate] = @ModifiedDate WHERE (([ProductCategoryID] = @Original_ProductCategoryID) AND ((@IsNull_ParentProductCategoryID = 1 AND [ParentProductCategoryID] IS NULL) OR ([ParentProductCategoryID] = @Original_ParentProductCategoryID)) AND ([Name] = @Original_Name) AND ([rowguid] = @Original_rowguid) AND ([ModifiedDate] = @Original_ModifiedDate));
SELECT ProductCategoryID, ParentProductCategoryID, Name, rowguid, ModifiedDate FROM SalesLT.ProductCategory WHERE (ProductCategoryID = @ProductCategoryID)";
            this._adapter.UpdateCommand.CommandType = CommandType.Text;
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ParentProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ParentProductCategoryID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsNull_ParentProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ParentProductCategoryID", DataRowVersion.Original, true, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ParentProductCategoryID", SqlDbType.Int, 0, ParameterDirection.Input, 0, 0, "ParentProductCategoryID", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Name", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Name", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_rowguid", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input, 0, 0, "rowguid", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_ModifiedDate", SqlDbType.DateTime, 0, ParameterDirection.Input, 0, 0, "ModifiedDate", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ProductCategoryID", SqlDbType.Int, 4, ParameterDirection.Input, 0, 0, "ProductCategoryID", DataRowVersion.Current, false, null, "", "", ""));
        }


        private void InitConnection()
        {
            this._connection = new FaultRetryConnection();
            this._connection.ConnectionString = Properties.Settings.Default.AdventureWorksLT2008ConnectionString;
        }


        private void InitCommandCollection()
        {
            this._commandCollection = new FaultRetryCommand[1];
            this._commandCollection[0] = new FaultRetryCommand();
            this._commandCollection[0].Connection = this.Connection;
            this._commandCollection[0].CommandText = "SELECT ProductCategoryID, ParentProductCategoryID, Name, rowguid, ModifiedDate FR" +
                "OM SalesLT.ProductCategory";
            this._commandCollection[0].CommandType = CommandType.Text;
        }



        public virtual int Fill(ProductCategoryDataTable dataTable)
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            if ((this.ClearBeforeFill == true))
            {
                dataTable.Clear();
            }
            int returnValue = this.Adapter.Fill(dataTable);
            return returnValue;
        }



        public virtual ProductCategoryDataTable GetData()
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            ProductCategoryDataTable dataTable = new ProductCategoryDataTable();
            this.Adapter.Fill(dataTable);
            return dataTable;
        }



        public virtual int Update(ProductCategoryDataTable dataTable)
        {
            return this.Adapter.Update(dataTable);
        }



        public virtual int Update(ProductDataSet dataSet)
        {
            return this.Adapter.Update(dataSet, "ProductCategory");
        }



        public virtual int Update(DataRow dataRow)
        {
            return this.Adapter.Update(new DataRow[] {
                        dataRow});
        }



        public virtual int Update(DataRow[] dataRows)
        {
            return this.Adapter.Update(dataRows);
        }



        public virtual int Delete(int Original_ProductCategoryID, Nullable<int> Original_ParentProductCategoryID, string Original_Name, System.Guid Original_rowguid, System.DateTime Original_ModifiedDate)
        {
            this.Adapter.DeleteCommand.Parameters[0].Value = ((int)(Original_ProductCategoryID));
            if ((Original_ParentProductCategoryID.HasValue == true))
            {
                this.Adapter.DeleteCommand.Parameters[1].Value = ((object)(0));
                this.Adapter.DeleteCommand.Parameters[2].Value = ((int)(Original_ParentProductCategoryID.Value));
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[1].Value = ((object)(1));
                this.Adapter.DeleteCommand.Parameters[2].Value = DBNull.Value;
            }
            if ((Original_Name == null))
            {
                throw new ArgumentNullException("Original_Name");
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[3].Value = ((string)(Original_Name));
            }
            this.Adapter.DeleteCommand.Parameters[4].Value = ((System.Guid)(Original_rowguid));
            this.Adapter.DeleteCommand.Parameters[5].Value = ((System.DateTime)(Original_ModifiedDate));
            ConnectionState previousConnectionState = this.Adapter.DeleteCommand.Connection.State;
            if (((this.Adapter.DeleteCommand.Connection.State & ConnectionState.Open)
                        != ConnectionState.Open))
            {
                this.Adapter.DeleteCommand.Connection.Open();
            }
            try
            {
                int returnValue = this.Adapter.DeleteCommand.ExecuteNonQuery();
                return returnValue;
            }
            finally
            {
                if ((previousConnectionState == ConnectionState.Closed))
                {
                    this.Adapter.DeleteCommand.Connection.Close();
                }
            }
        }



        public virtual int Insert(Nullable<int> ParentProductCategoryID, string Name, System.Guid rowguid, System.DateTime ModifiedDate)
        {
            if ((ParentProductCategoryID.HasValue == true))
            {
                this.Adapter.InsertCommand.Parameters[0].Value = ((int)(ParentProductCategoryID.Value));
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[0].Value = DBNull.Value;
            }
            if ((Name == null))
            {
                throw new ArgumentNullException("Name");
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[1].Value = ((string)(Name));
            }
            this.Adapter.InsertCommand.Parameters[2].Value = ((System.Guid)(rowguid));
            this.Adapter.InsertCommand.Parameters[3].Value = ((System.DateTime)(ModifiedDate));
            ConnectionState previousConnectionState = this.Adapter.InsertCommand.Connection.State;
            if (((this.Adapter.InsertCommand.Connection.State & ConnectionState.Open)
                        != ConnectionState.Open))
            {
                this.Adapter.InsertCommand.Connection.Open();
            }
            try
            {
                int returnValue = this.Adapter.InsertCommand.ExecuteNonQuery();
                return returnValue;
            }
            finally
            {
                if ((previousConnectionState == ConnectionState.Closed))
                {
                    this.Adapter.InsertCommand.Connection.Close();
                }
            }
        }



        public virtual int Update(Nullable<int> ParentProductCategoryID, string Name, System.Guid rowguid, System.DateTime ModifiedDate, int Original_ProductCategoryID, Nullable<int> Original_ParentProductCategoryID, string Original_Name, System.Guid Original_rowguid, System.DateTime Original_ModifiedDate, int ProductCategoryID)
        {
            if ((ParentProductCategoryID.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[0].Value = ((int)(ParentProductCategoryID.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[0].Value = DBNull.Value;
            }
            if ((Name == null))
            {
                throw new ArgumentNullException("Name");
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[1].Value = ((string)(Name));
            }
            this.Adapter.UpdateCommand.Parameters[2].Value = ((System.Guid)(rowguid));
            this.Adapter.UpdateCommand.Parameters[3].Value = ((System.DateTime)(ModifiedDate));
            this.Adapter.UpdateCommand.Parameters[4].Value = ((int)(Original_ProductCategoryID));
            if ((Original_ParentProductCategoryID.HasValue == true))
            {
                this.Adapter.UpdateCommand.Parameters[5].Value = ((object)(0));
                this.Adapter.UpdateCommand.Parameters[6].Value = ((int)(Original_ParentProductCategoryID.Value));
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[5].Value = ((object)(1));
                this.Adapter.UpdateCommand.Parameters[6].Value = DBNull.Value;
            }
            if ((Original_Name == null))
            {
                throw new ArgumentNullException("Original_Name");
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[7].Value = ((string)(Original_Name));
            }
            this.Adapter.UpdateCommand.Parameters[8].Value = ((System.Guid)(Original_rowguid));
            this.Adapter.UpdateCommand.Parameters[9].Value = ((System.DateTime)(Original_ModifiedDate));
            this.Adapter.UpdateCommand.Parameters[10].Value = ((int)(ProductCategoryID));
            ConnectionState previousConnectionState = this.Adapter.UpdateCommand.Connection.State;
            if (((this.Adapter.UpdateCommand.Connection.State & ConnectionState.Open)
                        != ConnectionState.Open))
            {
                this.Adapter.UpdateCommand.Connection.Open();
            }
            try
            {
                int returnValue = this.Adapter.UpdateCommand.ExecuteNonQuery();
                return returnValue;
            }
            finally
            {
                if ((previousConnectionState == ConnectionState.Closed))
                {
                    this.Adapter.UpdateCommand.Connection.Close();
                }
            }
        }



        public virtual int Update(Nullable<int> ParentProductCategoryID, string Name, System.Guid rowguid, System.DateTime ModifiedDate, int Original_ProductCategoryID, Nullable<int> Original_ParentProductCategoryID, string Original_Name, System.Guid Original_rowguid, System.DateTime Original_ModifiedDate)
        {
            return this.Update(ParentProductCategoryID, Name, rowguid, ModifiedDate, Original_ProductCategoryID, Original_ParentProductCategoryID, Original_Name, Original_rowguid, Original_ModifiedDate, Original_ProductCategoryID);
        }
    }

    /// <summary>
    ///TableAdapterManager is used to coordinate TableAdapters in the dataset to enable Hierarchical Update scenarios
    ///</summary>
    public class TableAdapterManager : Component
    {

        private UpdateOrderOption _updateOrder;

        private ProductTableAdapter _productTableAdapter;

        private ProductCategoryTableAdapter _productCategoryTableAdapter;

        private bool _backupDataSetBeforeUpdate;

        private IDbConnection _connection;


        public UpdateOrderOption UpdateOrder
        {
            get
            {
                return this._updateOrder;
            }
            set
            {
                this._updateOrder = value;
            }
        }


        public ProductTableAdapter ProductTableAdapter
        {
            get
            {
                return this._productTableAdapter;
            }
            set
            {
                this._productTableAdapter = value;
            }
        }


        public ProductCategoryTableAdapter ProductCategoryTableAdapter
        {
            get
            {
                return this._productCategoryTableAdapter;
            }
            set
            {
                this._productCategoryTableAdapter = value;
            }
        }


        public bool BackupDataSetBeforeUpdate
        {
            get
            {
                return this._backupDataSetBeforeUpdate;
            }
            set
            {
                this._backupDataSetBeforeUpdate = value;
            }
        }



        public IDbConnection Connection
        {
            get
            {
                if ((this._connection != null))
                {
                    return this._connection;
                }
                if (((this._productTableAdapter != null)
                            && (this._productTableAdapter.Connection != null)))
                {
                    return this._productTableAdapter.Connection;
                }
                if (((this._productCategoryTableAdapter != null)
                            && (this._productCategoryTableAdapter.Connection != null)))
                {
                    return this._productCategoryTableAdapter.Connection;
                }
                return null;
            }
            set
            {
                this._connection = value;
                if (this._productCategoryTableAdapter != null)
                    _productCategoryTableAdapter.Connection = (FaultRetryConnection)value;
                if (this._productTableAdapter != null)
                    _productTableAdapter.Connection = (FaultRetryConnection)value;
            }
        }



        public int TableAdapterInstanceCount
        {
            get
            {
                int count = 0;
                if ((this._productTableAdapter != null))
                {
                    count = (count + 1);
                }
                if ((this._productCategoryTableAdapter != null))
                {
                    count = (count + 1);
                }
                return count;
            }
        }

        /// <summary>
        ///Update rows in top-down order.
        ///</summary>

        private int UpdateUpdatedRows(ProductDataSet dataSet, List<DataRow> allChangedRows, List<DataRow> allAddedRows)
        {
            int result = 0;
            if ((this._productCategoryTableAdapter != null))
            {
                DataRow[] updatedRows = dataSet.ProductCategory.Select(null, null, DataViewRowState.ModifiedCurrent);
                updatedRows = this.GetRealUpdatedRows(updatedRows, allAddedRows);
                if (((updatedRows != null)
                            && (0 < updatedRows.Length)))
                {
                    this.SortSelfReferenceRows(updatedRows, dataSet.Relations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"], false);
                    result = (result + this._productCategoryTableAdapter.Update(updatedRows));
                    allChangedRows.AddRange(updatedRows);
                }
            }
            if ((this._productTableAdapter != null))
            {
                DataRow[] updatedRows = dataSet.Product.Select(null, null, DataViewRowState.ModifiedCurrent);
                updatedRows = this.GetRealUpdatedRows(updatedRows, allAddedRows);
                if (((updatedRows != null)
                            && (0 < updatedRows.Length)))
                {
                    result = (result + this._productTableAdapter.Update(updatedRows));
                    allChangedRows.AddRange(updatedRows);
                }
            }
            return result;
        }

        /// <summary>
        ///Insert rows in top-down order.
        ///</summary>

        private int UpdateInsertedRows(ProductDataSet dataSet, List<DataRow> allAddedRows)
        {
            int result = 0;
            if ((this._productCategoryTableAdapter != null))
            {
                DataRow[] addedRows = dataSet.ProductCategory.Select(null, null, DataViewRowState.Added);
                if (((addedRows != null)
                            && (0 < addedRows.Length)))
                {
                    this.SortSelfReferenceRows(addedRows, dataSet.Relations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"], false);
                    result = (result + this._productCategoryTableAdapter.Update(addedRows));
                    allAddedRows.AddRange(addedRows);
                }
            }
            if ((this._productTableAdapter != null))
            {
                DataRow[] addedRows = dataSet.Product.Select(null, null, DataViewRowState.Added);
                if (((addedRows != null)
                            && (0 < addedRows.Length)))
                {
                    result = (result + this._productTableAdapter.Update(addedRows));
                    allAddedRows.AddRange(addedRows);
                }
            }
            return result;
        }

        /// <summary>
        ///Delete rows in bottom-up order.
        ///</summary>

        private int UpdateDeletedRows(ProductDataSet dataSet, List<DataRow> allChangedRows)
        {
            int result = 0;
            if ((this._productTableAdapter != null))
            {
                DataRow[] deletedRows = dataSet.Product.Select(null, null, DataViewRowState.Deleted);
                if (((deletedRows != null)
                            && (0 < deletedRows.Length)))
                {
                    result = (result + this._productTableAdapter.Update(deletedRows));
                    allChangedRows.AddRange(deletedRows);
                }
            }
            if ((this._productCategoryTableAdapter != null))
            {
                DataRow[] deletedRows = dataSet.ProductCategory.Select(null, null, DataViewRowState.Deleted);
                if (((deletedRows != null)
                            && (0 < deletedRows.Length)))
                {
                    this.SortSelfReferenceRows(deletedRows, dataSet.Relations["FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID"], true);
                    result = (result + this._productCategoryTableAdapter.Update(deletedRows));
                    allChangedRows.AddRange(deletedRows);
                }
            }
            return result;
        }

        /// <summary>
        ///Remove inserted rows that become updated rows after calling TableAdapter.Update(inserted rows) first
        ///</summary>

        private DataRow[] GetRealUpdatedRows(DataRow[] updatedRows, List<DataRow> allAddedRows)
        {
            if (((updatedRows == null)
                        || (updatedRows.Length < 1)))
            {
                return updatedRows;
            }
            if (((allAddedRows == null)
                        || (allAddedRows.Count < 1)))
            {
                return updatedRows;
            }
            List<DataRow> realUpdatedRows = new List<DataRow>();
            for (int i = 0; (i < updatedRows.Length); i = (i + 1))
            {
                DataRow row = updatedRows[i];
                if ((allAddedRows.Contains(row) == false))
                {
                    realUpdatedRows.Add(row);
                }
            }
            return realUpdatedRows.ToArray();
        }

        /// <summary>
        ///Update all changes to the dataset.
        ///</summary>

        public virtual int UpdateAll(ProductDataSet dataSet)
        {
            if ((dataSet == null))
            {
                throw new ArgumentNullException("dataSet");
            }
            if ((dataSet.HasChanges() == false))
            {
                return 0;
            }
            if (((this._productTableAdapter != null)
                        && (this.MatchTableAdapterConnection(this._productTableAdapter.Connection) == false)))
            {
                throw new ArgumentException("All TableAdapters managed by a TableAdapterManager must use the same connection s" +
                        "tring.");
            }
            if (((this._productCategoryTableAdapter != null)
                        && (this.MatchTableAdapterConnection(this._productCategoryTableAdapter.Connection) == false)))
            {
                throw new ArgumentException("All TableAdapters managed by a TableAdapterManager must use the same connection s" +
                        "tring.");
            }
            IDbConnection workConnection = this.Connection;
            if ((workConnection == null))
            {
                throw new ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterMana" +
                        "ger TableAdapter property to a valid TableAdapter instance.");
            }
            bool workConnOpened = false;
            if (((workConnection.State & ConnectionState.Broken)
                        == ConnectionState.Broken))
            {
                workConnection.Close();
            }
            if ((workConnection.State == ConnectionState.Closed))
            {
                workConnection.Open();
                workConnOpened = true;
            }
            IDbTransaction workTransaction = workConnection.BeginTransaction();
            if ((workTransaction == null))
            {
                throw new ApplicationException("The transaction cannot begin. The current data connection does not support transa" +
                        "ctions or the current state is not allowing the transaction to begin.");
            }
            List<DataRow> allChangedRows = new List<DataRow>();
            List<DataRow> allAddedRows = new List<DataRow>();
            List<FaultRetryDataAdapter> adaptersWithAcceptChangesDuringUpdate = new List<FaultRetryDataAdapter>();
            Dictionary<object, IDbConnection> revertConnections = new Dictionary<object, IDbConnection>();
            int result = 0;
            DataSet backupDataSet = null;
            if (this.BackupDataSetBeforeUpdate)
            {
                backupDataSet = new DataSet();
                backupDataSet.Merge(dataSet);
            }
            try
            {
                // ---- Prepare for update -----------
                //
                if ((this._productTableAdapter != null))
                {
                    revertConnections.Add(this._productTableAdapter, this._productTableAdapter.Connection);
                    this._productTableAdapter.Connection = ((FaultRetryConnection)(workConnection));
                    this._productTableAdapter.Transaction = ((SqlTransaction)(workTransaction));
                    if (this._productTableAdapter.Adapter.AcceptChangesDuringUpdate)
                    {
                        this._productTableAdapter.Adapter.AcceptChangesDuringUpdate = false;
                        adaptersWithAcceptChangesDuringUpdate.Add(this._productTableAdapter.Adapter);
                    }
                }
                if ((this._productCategoryTableAdapter != null))
                {
                    revertConnections.Add(this._productCategoryTableAdapter, this._productCategoryTableAdapter.Connection);
                    this._productCategoryTableAdapter.Connection = ((FaultRetryConnection)(workConnection));
                    this._productCategoryTableAdapter.Transaction = ((SqlTransaction)(workTransaction));
                    if (this._productCategoryTableAdapter.Adapter.AcceptChangesDuringUpdate)
                    {
                        this._productCategoryTableAdapter.Adapter.AcceptChangesDuringUpdate = false;
                        adaptersWithAcceptChangesDuringUpdate.Add(this._productCategoryTableAdapter.Adapter);
                    }
                }
                // 
                //---- Perform updates -----------
                //
                if ((this.UpdateOrder == UpdateOrderOption.UpdateInsertDelete))
                {
                    result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                    result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                }
                else
                {
                    result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                    result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                }
                result = (result + this.UpdateDeletedRows(dataSet, allChangedRows));
                // 
                //---- Commit updates -----------
                //
                workTransaction.Commit();
                if ((0 < allAddedRows.Count))
                {
                    DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                    allAddedRows.CopyTo(rows);
                    for (int i = 0; (i < rows.Length); i = (i + 1))
                    {
                        DataRow row = rows[i];
                        row.AcceptChanges();
                    }
                }
                if ((0 < allChangedRows.Count))
                {
                    DataRow[] rows = new System.Data.DataRow[allChangedRows.Count];
                    allChangedRows.CopyTo(rows);
                    for (int i = 0; (i < rows.Length); i = (i + 1))
                    {
                        DataRow row = rows[i];
                        row.AcceptChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                workTransaction.Rollback();
                // ---- Restore the dataset -----------
                if (this.BackupDataSetBeforeUpdate)
                {
                    Debug.Assert((backupDataSet != null));
                    dataSet.Clear();
                    dataSet.Merge(backupDataSet);
                }
                else
                {
                    if ((0 < allAddedRows.Count))
                    {
                        DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                        allAddedRows.CopyTo(rows);
                        for (int i = 0; (i < rows.Length); i = (i + 1))
                        {
                            DataRow row = rows[i];
                            row.AcceptChanges();
                            row.SetAdded();
                        }
                    }
                }
                throw ex;
            }
            finally
            {
                if (workConnOpened)
                {
                    workConnection.Close();
                }
                if ((this._productTableAdapter != null))
                {
                    this._productTableAdapter.Connection = ((FaultRetryConnection)(revertConnections[this._productTableAdapter]));
                    this._productTableAdapter.Transaction = null;
                }
                if ((this._productCategoryTableAdapter != null))
                {
                    this._productCategoryTableAdapter.Connection = ((FaultRetryConnection)(revertConnections[this._productCategoryTableAdapter]));
                    this._productCategoryTableAdapter.Transaction = null;
                }
                if ((0 < adaptersWithAcceptChangesDuringUpdate.Count))
                {
                    FaultRetryDataAdapter[] adapters = new FaultRetryDataAdapter[adaptersWithAcceptChangesDuringUpdate.Count];
                    adaptersWithAcceptChangesDuringUpdate.CopyTo(adapters);
                    for (int i = 0; (i < adapters.Length); i = (i + 1))
                    {
                        FaultRetryDataAdapter adapter = adapters[i];
                        adapter.AcceptChangesDuringUpdate = true;
                    }
                }
            }
            return result;
        }


        protected virtual void SortSelfReferenceRows(DataRow[] rows, DataRelation relation, bool childFirst)
        {
            Array.Sort<DataRow>(rows, new SelfReferenceComparer(relation, childFirst));
        }


        protected virtual bool MatchTableAdapterConnection(IDbConnection inputConnection)
        {
            if ((this._connection != null))
            {
                return true;
            }
            if (((this.Connection == null)
                        || (inputConnection == null)))
            {
                return true;
            }
            if (string.Equals(this.Connection.ConnectionString, inputConnection.ConnectionString, StringComparison.Ordinal))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        ///Update Order Option
        ///</summary>

        public enum UpdateOrderOption
        {

            InsertUpdateDelete = 0,

            UpdateInsertDelete = 1,
        }

        /// <summary>
        ///Used to sort self-referenced table's rows
        ///</summary>

        private class SelfReferenceComparer : object, IComparer<DataRow>
        {

            private DataRelation _relation;

            private int _childFirst;


            internal SelfReferenceComparer(DataRelation relation, bool childFirst)
            {
                this._relation = relation;
                if (childFirst)
                {
                    this._childFirst = -1;
                }
                else
                {
                    this._childFirst = 1;
                }
            }


            private bool IsChildAndParent(DataRow child, DataRow parent)
            {
                Debug.Assert((child != null));
                Debug.Assert((parent != null));
                DataRow newParent = child.GetParentRow(this._relation, DataRowVersion.Default);
                for (
                ; ((newParent != null)
                            && ((object.ReferenceEquals(newParent, child) == false)
                            && (object.ReferenceEquals(newParent, parent) == false)));
                )
                {
                    newParent = newParent.GetParentRow(this._relation, DataRowVersion.Default);
                }
                if ((newParent == null))
                {
                    for (newParent = child.GetParentRow(this._relation, DataRowVersion.Original); ((newParent != null)
                                && ((object.ReferenceEquals(newParent, child) == false)
                                && (object.ReferenceEquals(newParent, parent) == false)));
                    )
                    {
                        newParent = newParent.GetParentRow(this._relation, DataRowVersion.Original);
                    }
                }
                if (object.ReferenceEquals(newParent, parent))
                {
                    return true;
                }
                return false;
            }


            public int Compare(DataRow row1, DataRow row2)
            {
                if (object.ReferenceEquals(row1, row2))
                {
                    return 0;
                }
                if ((row1 == null))
                {
                    return -1;
                }
                if ((row2 == null))
                {
                    return 1;
                }

                // Is row1 the child or grandchild of row2
                if (this.IsChildAndParent(row1, row2))
                {
                    return this._childFirst;
                }

                // Is row2 the child or grandchild of row1
                if (this.IsChildAndParent(row2, row1))
                {
                    return (-1 * this._childFirst);
                }
                return 0;
            }
        }
    }
}

